@tetherto/wdk-wallet-evm 1.0.0-beta.19 → 1.0.0-beta.20
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/README.md +1 -1
- package/index.js +5 -0
- package/package.json +3 -2
- package/src/signers/seed-signer-evm.js +1 -1
- package/src/utils/tx-populator-evm.js +13 -1
- package/src/wallet-account-evm.js +21 -14
- package/src/wallet-account-read-only-evm.js +87 -34
- package/src/wallet-manager-evm.js +1 -1
- package/types/index.d.ts +4 -0
- package/types/src/signers/seed-signer-evm.d.ts +1 -1
- package/types/src/wallet-account-evm.d.ts +17 -5
- package/types/src/wallet-account-read-only-evm.d.ts +46 -16
- package/types/src/wallet-manager-evm.d.ts +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
**Note**: This package is currently in beta. Please test thoroughly in development environments before using in production.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
An EVM wallet module for WDK (Wallet Development Kit) by Tether. This package provides a clean API for creating, managing, and interacting with Ethereum-compatible wallets using BIP-39 seed phrases and EVM-specific derivation paths.
|
|
11
11
|
|
|
12
12
|
## About WDK
|
|
13
13
|
|
package/index.js
CHANGED
|
@@ -20,11 +20,14 @@
|
|
|
20
20
|
/** @typedef {import('ethers').AuthorizationLike} AuthorizationLike */
|
|
21
21
|
/** @typedef {import('ethers').TransactionReceipt} EvmTransactionReceipt */
|
|
22
22
|
/** @typedef {import('ethers').TransactionResponse} EvmTransactionResponse */
|
|
23
|
+
/** @typedef {import('ethers').TransactionRequest} EvmTransactionRequest */
|
|
24
|
+
/** @typedef {import('ethers').BlobLike} BlobLike */
|
|
23
25
|
|
|
24
26
|
/** @typedef {import('@tetherto/wdk-wallet').FeeRates} FeeRates */
|
|
25
27
|
/** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
|
|
26
28
|
/** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
|
|
27
29
|
/** @typedef {import('@tetherto/wdk-wallet').TransferResult} TransferResult */
|
|
30
|
+
/** @typedef {import('@tetherto/wdk-wallet').TransferOptions} TransferOptions */
|
|
28
31
|
/** @typedef {import('@tetherto/wdk-wallet').Finality} Finality */
|
|
29
32
|
/** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
|
|
30
33
|
/** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionTarget} WaitForTransactionTarget */
|
|
@@ -33,11 +36,13 @@
|
|
|
33
36
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').TypedData} TypedData */
|
|
34
37
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').DelegationInfo} DelegationInfo */
|
|
35
38
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransaction} EvmTransaction */
|
|
39
|
+
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmGasOverrides} EvmGasOverrides */
|
|
36
40
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransferOptions} EvmTransferOptions */
|
|
37
41
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
38
42
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransactionDetails} EvmTransactionDetails */
|
|
39
43
|
|
|
40
44
|
/** @typedef {import('./src/wallet-account-evm.js').ApproveOptions} ApproveOptions */
|
|
45
|
+
/** @typedef {import('./src/wallet-account-evm.js').EvmApproveOptions} EvmApproveOptions */
|
|
41
46
|
|
|
42
47
|
/** @typedef {import('./src/utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
|
|
43
48
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tetherto/wdk-wallet-evm",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0-beta.20",
|
|
4
|
+
"description": "EVM wallet module for WDK (Wallet Development Kit) by Tether.",
|
|
5
|
+
"homepage": "https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm/",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"wdk",
|
|
7
8
|
"wallet",
|
|
@@ -160,7 +160,7 @@ export default class SeedSignerEvm extends ISignerEvm {
|
|
|
160
160
|
* Create a SeedSignerEvm.
|
|
161
161
|
* Provide either a mnemonic/seed or an existing root via opts.root (for children root is not stored internally)
|
|
162
162
|
*
|
|
163
|
-
* @param {string|Uint8Array|null} seed - BIP-39 mnemonic or seed bytes. Omit when providing `opts.root`.
|
|
163
|
+
* @param {string|Uint8Array|null} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes). Omit when providing `opts.root`.
|
|
164
164
|
* @param {SeedSignerEvmOpts} [opts] - Construction options for root reuse, direct child derivation or path definition (default is index 0).
|
|
165
165
|
* @throws {ValueError} If neither a seed nor a root is provided, or if both are provided.
|
|
166
166
|
* @throws {ValueError} If a seed is provided but is not a valid BIP-39 mnemonic.
|
|
@@ -76,6 +76,9 @@ export async function populateTransactionEvm (provider, from, tx) {
|
|
|
76
76
|
if ((explicitType === 3 || hasBlobs) && hasLegacy) {
|
|
77
77
|
throw new ValueError('blob transaction does not support gasPrice')
|
|
78
78
|
}
|
|
79
|
+
if ((explicitType === 4 || (explicitType == null && hasAuthList)) && hasLegacy) {
|
|
80
|
+
throw new ValueError('eip-7702 transaction does not support gasPrice')
|
|
81
|
+
}
|
|
79
82
|
|
|
80
83
|
const feeData = await provider.getFeeData()
|
|
81
84
|
|
|
@@ -143,7 +146,16 @@ export async function populateTransactionEvm (provider, from, tx) {
|
|
|
143
146
|
return populated
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
|
|
149
|
+
if (type === 4) {
|
|
150
|
+
populated.type = 4
|
|
151
|
+
populated.maxFeePerGas = tx.maxFeePerGas ?? feeData.maxFeePerGas
|
|
152
|
+
populated.maxPriorityFeePerGas = tx.maxPriorityFeePerGas ?? feeData.maxPriorityFeePerGas
|
|
153
|
+
if (hasAccessList) populated.accessList = tx.accessList
|
|
154
|
+
if (tx.authorizationList != null) populated.authorizationList = tx.authorizationList
|
|
155
|
+
return populated
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Future types; pass-through
|
|
147
159
|
populated.type = type
|
|
148
160
|
if (hasAccessList) populated.accessList = tx.accessList
|
|
149
161
|
if (hasLegacy) {
|
|
@@ -39,6 +39,7 @@ import { populateTransactionEvm } from './utils/tx-populator-evm.js'
|
|
|
39
39
|
/** @typedef {import('./wallet-account-read-only-evm.js').TypedData} TypedData */
|
|
40
40
|
/** @typedef {import('./wallet-account-read-only-evm.js').EvmTransaction} EvmTransaction */
|
|
41
41
|
/** @typedef {import('./wallet-account-read-only-evm.js').EvmTransferOptions} EvmTransferOptions */
|
|
42
|
+
/** @typedef {import('./wallet-account-read-only-evm.js').EvmGasOverrides} EvmGasOverrides */
|
|
42
43
|
/** @typedef {import('./wallet-account-read-only-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
43
44
|
|
|
44
45
|
/**
|
|
@@ -48,6 +49,12 @@ import { populateTransactionEvm } from './utils/tx-populator-evm.js'
|
|
|
48
49
|
* @property {number | bigint} amount - The amount of tokens to approve to the spender.
|
|
49
50
|
*/
|
|
50
51
|
|
|
52
|
+
/**
|
|
53
|
+
* The options of a token approval, extended with the optional gas overrides of an evm transaction.
|
|
54
|
+
*
|
|
55
|
+
* @typedef {ApproveOptions & EvmGasOverrides} EvmApproveOptions
|
|
56
|
+
*/
|
|
57
|
+
|
|
51
58
|
const USDT_MAINNET_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7'
|
|
52
59
|
|
|
53
60
|
const DELEGATION_TX_GAS_LIMIT = 100_000
|
|
@@ -59,7 +66,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
59
66
|
* given BIP-44 path.
|
|
60
67
|
*
|
|
61
68
|
* @overload
|
|
62
|
-
* @param {string | Uint8Array} seed -
|
|
69
|
+
* @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
63
70
|
* @param {string} path - The BIP-44 derivation path (e.g. "0'/0/0").
|
|
64
71
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
65
72
|
*/
|
|
@@ -224,9 +231,16 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
224
231
|
/**
|
|
225
232
|
* Quotes the costs of a send transaction operation.
|
|
226
233
|
*
|
|
234
|
+
* The transaction is always simulated through gas estimation, so one that would revert is rejected here instead of
|
|
235
|
+
* reaching the signer. A `gasLimit` set on the transaction replaces the estimated gas in the quote, and a `maxFeePerGas`
|
|
236
|
+
* (or `gasPrice`) set on it replaces the fee rate fetched from the provider, so the quote is the transaction's maximum
|
|
237
|
+
* cost as it will be sent.
|
|
238
|
+
* A signed raw transaction is simulated the same way and quoted from its own gas limit and fee cap.
|
|
239
|
+
*
|
|
227
240
|
* @param {EvmTransaction | string} tx - The transaction, or a signed raw transaction as a hex string.
|
|
228
241
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
229
242
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
243
|
+
* @throws {Error} If the simulation of the transaction reverts, as an ethers error with code `CALL_EXCEPTION`.
|
|
230
244
|
*/
|
|
231
245
|
async quoteSendTransaction (tx) {
|
|
232
246
|
if (typeof tx === 'string') {
|
|
@@ -236,17 +250,9 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
236
250
|
|
|
237
251
|
const { from, to, value, data, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, type, nonce, chainId, authorizationList } = Transaction.from(tx)
|
|
238
252
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const gas = transaction.authorizationList
|
|
242
|
-
? await this._estimateGasWithAuthList(transaction)
|
|
243
|
-
: await this._provider.estimateGas(transaction)
|
|
244
|
-
|
|
245
|
-
const fees = await this._provider.getFeeData()
|
|
246
|
-
|
|
247
|
-
const feeRate = fees.maxFeePerGas || fees.gasPrice
|
|
253
|
+
await this._estimateGas({ from, to, value, data, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, type, nonce, chainId, authorizationList })
|
|
248
254
|
|
|
249
|
-
return { fee:
|
|
255
|
+
return { fee: gasLimit * (maxFeePerGas ?? gasPrice) }
|
|
250
256
|
}
|
|
251
257
|
|
|
252
258
|
return await super.quoteSendTransaction(tx)
|
|
@@ -255,7 +261,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
255
261
|
/**
|
|
256
262
|
* Transfers a token to another address.
|
|
257
263
|
*
|
|
258
|
-
* @param {EvmTransferOptions} options - The transfer's options.
|
|
264
|
+
* @param {EvmTransferOptions} options - The transfer's options, including any gas overrides to carry onto the transaction.
|
|
259
265
|
* @returns {Promise<TransferResult>} The transfer's result.
|
|
260
266
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
261
267
|
* @throws {MaximumFeeExceededError} If the transfer's cost exceeds the maximum transfer fee option.
|
|
@@ -281,7 +287,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
281
287
|
/**
|
|
282
288
|
* Approves a specific amount of tokens to a spender.
|
|
283
289
|
*
|
|
284
|
-
* @param {
|
|
290
|
+
* @param {EvmApproveOptions} options - The approve options, including any gas overrides to carry onto the transaction.
|
|
285
291
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
286
292
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
287
293
|
* @throws {ValueError} If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
|
|
@@ -309,7 +315,8 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
309
315
|
const tx = {
|
|
310
316
|
to: token,
|
|
311
317
|
value: 0,
|
|
312
|
-
data: contract.interface.encodeFunctionData('approve', [spender, amount])
|
|
318
|
+
data: contract.interface.encodeFunctionData('approve', [spender, amount]),
|
|
319
|
+
...WalletAccountReadOnlyEvm._getGasOverrides(options)
|
|
313
320
|
}
|
|
314
321
|
|
|
315
322
|
return await this.sendTransaction(tx)
|
|
@@ -27,13 +27,16 @@ import FailoverProvider from '@tetherto/wdk-failover-provider'
|
|
|
27
27
|
/** @typedef {import('ethers').TypedDataDomain} TypedDataDomain */
|
|
28
28
|
/** @typedef {import('ethers').TypedDataField} TypedDataField */
|
|
29
29
|
/** @typedef {import('ethers').AuthorizationLike} AuthorizationLike */
|
|
30
|
+
/** @typedef {import('ethers').BlobLike} BlobLike */
|
|
30
31
|
/** @typedef {import('ethers').TransactionReceipt} EvmTransactionReceipt */
|
|
31
32
|
/** @typedef {import('ethers').TransactionResponse} EvmTransactionResponse */
|
|
33
|
+
/** @typedef {import('ethers').TransactionRequest} EvmTransactionRequest */
|
|
32
34
|
|
|
33
35
|
/** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
|
|
34
36
|
/** @typedef {import('@tetherto/wdk-wallet').TransferResult} TransferResult */
|
|
35
37
|
/** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
|
|
36
38
|
/** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
|
|
39
|
+
/** @typedef {import('@tetherto/wdk-wallet').TransferOptions} TransferOptions */
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* The EVM-specific fields added to a normalized transaction receipt.
|
|
@@ -68,15 +71,23 @@ import FailoverProvider from '@tetherto/wdk-failover-provider'
|
|
|
68
71
|
* @property {number} [type] - The transaction type (e.g. 4 for ERC-7702).
|
|
69
72
|
* @property {number} [nonce] - The transaction nonce.
|
|
70
73
|
* @property {number | bigint} [chainId] - The chain ID of the network.
|
|
74
|
+
* @property {number | bigint} [maxFeePerBlobGas] - The maximum price (in wei) per unit of blob gas this transaction will pay for [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) blob data. Required for type 3 (blob) transactions.
|
|
75
|
+
* @property {BlobLike[]} [blobs] - The blobs of an [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) type 3 transaction.
|
|
76
|
+
* @property {string[]} [blobVersionedHashes] - The versioned hashes of the blobs of an [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) type 3 transaction.
|
|
71
77
|
* @property {AuthorizationLike[]} [authorizationList] - An optional list of ERC-7702 signed authorizations for type 4 transactions.
|
|
72
78
|
*/
|
|
73
79
|
|
|
74
80
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
* The gas and fee fields of an evm transaction that can be set on transfer and approve options.
|
|
82
|
+
*
|
|
83
|
+
* @typedef {Pick<EvmTransaction, 'gasLimit' | 'gasPrice' | 'maxFeePerGas' | 'maxPriorityFeePerGas'>} EvmGasOverrides
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The options of a token transfer, extended with the optional gas overrides and ERC-7702 authorizations of an evm
|
|
88
|
+
* transaction.
|
|
89
|
+
*
|
|
90
|
+
* @typedef {TransferOptions & EvmGasOverrides & Pick<EvmTransaction, 'authorizationList'>} EvmTransferOptions
|
|
80
91
|
*/
|
|
81
92
|
|
|
82
93
|
/**
|
|
@@ -268,9 +279,15 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
268
279
|
/**
|
|
269
280
|
* Quotes the costs of a send transaction operation.
|
|
270
281
|
*
|
|
282
|
+
* The transaction is always simulated through gas estimation, so one that would revert is rejected here instead of
|
|
283
|
+
* reaching the signer. A `gasLimit` set on the transaction replaces the estimated gas in the quote, and a `maxFeePerGas`
|
|
284
|
+
* (or `gasPrice`) set on it replaces the fee rate fetched from the provider, so the quote is the transaction's maximum
|
|
285
|
+
* cost as it will be sent.
|
|
286
|
+
*
|
|
271
287
|
* @param {EvmTransaction} tx - The transaction.
|
|
272
288
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
273
289
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
290
|
+
* @throws {Error} If the simulation of the transaction reverts, as an ethers error with code `CALL_EXCEPTION`.
|
|
274
291
|
*/
|
|
275
292
|
async quoteSendTransaction (tx) {
|
|
276
293
|
if (!this._provider) {
|
|
@@ -279,21 +296,18 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
279
296
|
|
|
280
297
|
const from = await this.getAddress()
|
|
281
298
|
|
|
282
|
-
const
|
|
283
|
-
? await this._estimateGasWithAuthList({ from, ...tx })
|
|
284
|
-
: await this._provider.estimateGas({ from, ...tx })
|
|
299
|
+
const estimatedGas = await this._estimateGas({ from, ...tx })
|
|
285
300
|
|
|
286
|
-
const
|
|
301
|
+
const gas = tx.gasLimit ?? estimatedGas
|
|
302
|
+
const feeRate = tx.maxFeePerGas ?? tx.gasPrice ?? await this._getFeeRate()
|
|
287
303
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return { fee: gas * feeRate }
|
|
304
|
+
return { fee: BigInt(gas) * BigInt(feeRate) }
|
|
291
305
|
}
|
|
292
306
|
|
|
293
307
|
/**
|
|
294
308
|
* Quotes the costs of a transfer operation.
|
|
295
309
|
*
|
|
296
|
-
* @param {EvmTransferOptions} options - The transfer's options.
|
|
310
|
+
* @param {EvmTransferOptions} options - The transfer's options, including any gas overrides to carry onto the transaction.
|
|
297
311
|
* @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
|
|
298
312
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
299
313
|
*/
|
|
@@ -516,6 +530,62 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
516
530
|
}
|
|
517
531
|
}
|
|
518
532
|
|
|
533
|
+
/**
|
|
534
|
+
* Estimates the gas of a transaction by simulating it against the connected provider, using the authorization-list
|
|
535
|
+
* aware estimation for ERC-7702 transactions.
|
|
536
|
+
*
|
|
537
|
+
* @protected
|
|
538
|
+
* @param {EvmTransactionRequest} tx - The transaction to simulate, including its `from` address.
|
|
539
|
+
* @returns {Promise<bigint>} The gas units the simulated transaction consumed.
|
|
540
|
+
*/
|
|
541
|
+
async _estimateGas (tx) {
|
|
542
|
+
return tx.authorizationList
|
|
543
|
+
? await this._estimateGasWithAuthList(tx)
|
|
544
|
+
: await this._provider.estimateGas(tx)
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Extracts the gas and fee overrides set on transfer or approve options.
|
|
549
|
+
*
|
|
550
|
+
* @protected
|
|
551
|
+
* @param {EvmGasOverrides} options - The options to read the overrides from.
|
|
552
|
+
* @returns {EvmGasOverrides} Only the gas and fee fields that are set on the options.
|
|
553
|
+
*/
|
|
554
|
+
static _getGasOverrides (options) {
|
|
555
|
+
const overrides = {}
|
|
556
|
+
|
|
557
|
+
for (const field of ['gasLimit', 'gasPrice', 'maxFeePerGas', 'maxPriorityFeePerGas']) {
|
|
558
|
+
if (options[field] !== undefined) overrides[field] = options[field]
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return overrides
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Returns an evm transaction to execute the given token transfer.
|
|
566
|
+
*
|
|
567
|
+
* @protected
|
|
568
|
+
* @param {EvmTransferOptions} options - The transfer's options, including any gas overrides and ERC-7702 authorizations to carry onto the transaction.
|
|
569
|
+
* @returns {Promise<EvmTransaction>} The ERC-20 transfer call as an evm transaction, with the options' gas overrides and authorizations applied.
|
|
570
|
+
*/
|
|
571
|
+
static async _getTransferTransaction (options) {
|
|
572
|
+
const { token, recipient, amount, authorizationList } = options
|
|
573
|
+
|
|
574
|
+
const abi = ['function transfer(address to, uint256 amount) returns (bool)']
|
|
575
|
+
|
|
576
|
+
const contract = new Contract(token, abi)
|
|
577
|
+
|
|
578
|
+
const tx = {
|
|
579
|
+
to: token,
|
|
580
|
+
value: 0,
|
|
581
|
+
data: contract.interface.encodeFunctionData('transfer', [recipient, amount]),
|
|
582
|
+
...WalletAccountReadOnlyEvm._getGasOverrides(options),
|
|
583
|
+
authorizationList
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return tx
|
|
587
|
+
}
|
|
588
|
+
|
|
519
589
|
/** @private */
|
|
520
590
|
async _estimateGasWithAuthList ({ from, to, value, data, authorizationList }) {
|
|
521
591
|
const formatAuth = (auth) => {
|
|
@@ -549,27 +619,10 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
549
619
|
return BigInt(result)
|
|
550
620
|
}
|
|
551
621
|
|
|
552
|
-
/**
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
* @protected
|
|
556
|
-
* @param {EvmTransferOptions} options - The transfer's options.
|
|
557
|
-
* @returns {Promise<EvmTransaction>} The evm transaction.
|
|
558
|
-
*/
|
|
559
|
-
static async _getTransferTransaction (options) {
|
|
560
|
-
const { token, recipient, amount, authorizationList } = options
|
|
561
|
-
|
|
562
|
-
const abi = ['function transfer(address to, uint256 amount) returns (bool)']
|
|
563
|
-
|
|
564
|
-
const contract = new Contract(token, abi)
|
|
565
|
-
|
|
566
|
-
const tx = {
|
|
567
|
-
to: token,
|
|
568
|
-
value: 0,
|
|
569
|
-
data: contract.interface.encodeFunctionData('transfer', [recipient, amount]),
|
|
570
|
-
authorizationList
|
|
571
|
-
}
|
|
622
|
+
/** @private */
|
|
623
|
+
async _getFeeRate () {
|
|
624
|
+
const { maxFeePerGas, gasPrice } = await this._provider.getFeeData()
|
|
572
625
|
|
|
573
|
-
return
|
|
626
|
+
return maxFeePerGas || gasPrice
|
|
574
627
|
}
|
|
575
628
|
}
|
|
@@ -53,7 +53,7 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
53
53
|
* derive child accounts); non-derivable signers (e.g. private-key signers) are not allowed
|
|
54
54
|
* as the default but may be registered by name via {@link addSigner} - If not adding to your global account managment for using just one non derivable signer create a standalone account.
|
|
55
55
|
*
|
|
56
|
-
* @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}.
|
|
56
|
+
* @param {string|Uint8Array|ISigner} seedOrSigner - A BIP-39 mnemonic seed phrase, a raw BIP-32 master seed (16-64 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}.
|
|
57
57
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
58
58
|
* @throws {InvalidSignerError} If the default signer doesn't support account derivation.
|
|
59
59
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -8,10 +8,12 @@ export type Authorization = import("ethers").Authorization;
|
|
|
8
8
|
export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
9
9
|
export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
|
|
10
10
|
export type EvmTransactionResponse = import("ethers").TransactionResponse;
|
|
11
|
+
export type EvmTransactionRequest = import("ethers").TransactionRequest;
|
|
11
12
|
export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
|
|
12
13
|
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
13
14
|
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
14
15
|
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
16
|
+
export type TransferOptions = import("@tetherto/wdk-wallet").TransferOptions;
|
|
15
17
|
export type Finality = import("@tetherto/wdk-wallet").Finality;
|
|
16
18
|
export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
|
|
17
19
|
export type WaitForTransactionTarget = import("@tetherto/wdk-wallet").WaitForTransactionTarget;
|
|
@@ -19,8 +21,10 @@ export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTr
|
|
|
19
21
|
export type TypedData = import("./src/wallet-account-read-only-evm.js").TypedData;
|
|
20
22
|
export type DelegationInfo = import("./src/wallet-account-read-only-evm.js").DelegationInfo;
|
|
21
23
|
export type EvmTransaction = import("./src/wallet-account-read-only-evm.js").EvmTransaction;
|
|
24
|
+
export type EvmGasOverrides = import("./src/wallet-account-read-only-evm.js").EvmGasOverrides;
|
|
22
25
|
export type EvmTransferOptions = import("./src/wallet-account-read-only-evm.js").EvmTransferOptions;
|
|
23
26
|
export type EvmWalletConfig = import("./src/wallet-account-read-only-evm.js").EvmWalletConfig;
|
|
24
27
|
export type EvmTransactionDetails = import("./src/wallet-account-read-only-evm.js").EvmTransactionDetails;
|
|
25
28
|
export type ApproveOptions = import("./src/wallet-account-evm.js").ApproveOptions;
|
|
29
|
+
export type EvmApproveOptions = import("./src/wallet-account-evm.js").EvmApproveOptions;
|
|
26
30
|
export type UnsignedEvmTransaction = import("./src/utils/tx-populator-evm.js").UnsignedEvmTransaction;
|
|
@@ -126,7 +126,7 @@ export default class SeedSignerEvm extends ISignerEvm {
|
|
|
126
126
|
* Create a SeedSignerEvm.
|
|
127
127
|
* Provide a mnemonic/seed (children built via {@link derive} pass a shared root internally).
|
|
128
128
|
*
|
|
129
|
-
* @param {string|Uint8Array|null} seed - BIP-39 mnemonic or seed bytes. Omit when providing `opts.root`.
|
|
129
|
+
* @param {string|Uint8Array|null} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 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
131
|
* @throws {ValueError} If neither a seed nor a root is provided, or if both are provided.
|
|
132
132
|
* @throws {ValueError} If a seed is provided but is not a valid BIP-39 mnemonic.
|
|
@@ -12,7 +12,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
12
12
|
* Creates a new evm wallet account from a BIP-39 seed, deriving the account's key at the
|
|
13
13
|
* given BIP-44 path.
|
|
14
14
|
*
|
|
15
|
-
* @param {string | Uint8Array} seed -
|
|
15
|
+
* @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
16
16
|
* @param {string} path - The BIP-44 derivation path (e.g. "0'/0/0").
|
|
17
17
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
18
18
|
*/
|
|
@@ -99,15 +99,22 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
99
99
|
/**
|
|
100
100
|
* Quotes the costs of a send transaction operation.
|
|
101
101
|
*
|
|
102
|
-
*
|
|
102
|
+
* The transaction is always simulated through gas estimation, so one that would revert is rejected here instead of
|
|
103
|
+
* reaching the signer. A `gasLimit` set on the transaction replaces the estimated gas in the quote, and a `maxFeePerGas`
|
|
104
|
+
* (or `gasPrice`) set on it replaces the fee rate fetched from the provider, so the quote is the transaction's maximum
|
|
105
|
+
* cost as it will be sent.
|
|
106
|
+
* A signed raw transaction is simulated the same way and quoted from its own gas limit and fee cap.
|
|
107
|
+
*
|
|
108
|
+
* @param {EvmTransaction | string} tx - The transaction, or a signed raw transaction as a hex string.
|
|
103
109
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
104
110
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
111
|
+
* @throws {Error} If the simulation of the transaction reverts, as an ethers error with code `CALL_EXCEPTION`.
|
|
105
112
|
*/
|
|
106
113
|
quoteSendTransaction(tx: EvmTransaction | string): Promise<Omit<TransactionResult, "hash">>;
|
|
107
114
|
/**
|
|
108
115
|
* Transfers a token to another address.
|
|
109
116
|
*
|
|
110
|
-
* @param {EvmTransferOptions} options - The transfer's options.
|
|
117
|
+
* @param {EvmTransferOptions} options - The transfer's options, including any gas overrides to carry onto the transaction.
|
|
111
118
|
* @returns {Promise<TransferResult>} The transfer's result.
|
|
112
119
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
113
120
|
* @throws {MaximumFeeExceededError} If the transfer's cost exceeds the maximum transfer fee option.
|
|
@@ -116,12 +123,12 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
116
123
|
/**
|
|
117
124
|
* Approves a specific amount of tokens to a spender.
|
|
118
125
|
*
|
|
119
|
-
* @param {
|
|
126
|
+
* @param {EvmApproveOptions} options - The approve options, including any gas overrides to carry onto the transaction.
|
|
120
127
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
121
128
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
122
129
|
* @throws {ValueError} If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
|
|
123
130
|
*/
|
|
124
|
-
approve(options:
|
|
131
|
+
approve(options: EvmApproveOptions): Promise<TransactionResult>;
|
|
125
132
|
/**
|
|
126
133
|
* Returns a read-only copy of the account.
|
|
127
134
|
*
|
|
@@ -170,6 +177,7 @@ export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
|
170
177
|
export type TypedData = import("./wallet-account-read-only-evm.js").TypedData;
|
|
171
178
|
export type EvmTransaction = import("./wallet-account-read-only-evm.js").EvmTransaction;
|
|
172
179
|
export type EvmTransferOptions = import("./wallet-account-read-only-evm.js").EvmTransferOptions;
|
|
180
|
+
export type EvmGasOverrides = import("./wallet-account-read-only-evm.js").EvmGasOverrides;
|
|
173
181
|
export type EvmWalletConfig = import("./wallet-account-read-only-evm.js").EvmWalletConfig;
|
|
174
182
|
export type ApproveOptions = {
|
|
175
183
|
/**
|
|
@@ -185,4 +193,8 @@ export type ApproveOptions = {
|
|
|
185
193
|
*/
|
|
186
194
|
amount: number | bigint;
|
|
187
195
|
};
|
|
196
|
+
/**
|
|
197
|
+
* The options of a token approval, extended with the optional gas overrides of an evm transaction.
|
|
198
|
+
*/
|
|
199
|
+
export type EvmApproveOptions = ApproveOptions & EvmGasOverrides;
|
|
188
200
|
import WalletAccountReadOnlyEvm from './wallet-account-read-only-evm.js';
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the gas and fee overrides set on transfer or approve options.
|
|
4
|
+
*
|
|
5
|
+
* @protected
|
|
6
|
+
* @param {EvmGasOverrides} options - The options to read the overrides from.
|
|
7
|
+
* @returns {EvmGasOverrides} Only the gas and fee fields that are set on the options.
|
|
8
|
+
*/
|
|
9
|
+
protected static _getGasOverrides(options: EvmGasOverrides): EvmGasOverrides;
|
|
2
10
|
/**
|
|
3
11
|
* Returns an evm transaction to execute the given token transfer.
|
|
4
12
|
*
|
|
5
13
|
* @protected
|
|
6
|
-
* @param {EvmTransferOptions} options - The transfer's options.
|
|
7
|
-
* @returns {Promise<EvmTransaction>} The evm transaction.
|
|
14
|
+
* @param {EvmTransferOptions} options - The transfer's options, including any gas overrides and ERC-7702 authorizations to carry onto the transaction.
|
|
15
|
+
* @returns {Promise<EvmTransaction>} The ERC-20 transfer call as an evm transaction, with the options' gas overrides and authorizations applied.
|
|
8
16
|
*/
|
|
9
17
|
protected static _getTransferTransaction(options: EvmTransferOptions): Promise<EvmTransaction>;
|
|
10
18
|
/**
|
|
@@ -60,15 +68,21 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
60
68
|
/**
|
|
61
69
|
* Quotes the costs of a send transaction operation.
|
|
62
70
|
*
|
|
71
|
+
* The transaction is always simulated through gas estimation, so one that would revert is rejected here instead of
|
|
72
|
+
* reaching the signer. A `gasLimit` set on the transaction replaces the estimated gas in the quote, and a `maxFeePerGas`
|
|
73
|
+
* (or `gasPrice`) set on it replaces the fee rate fetched from the provider, so the quote is the transaction's maximum
|
|
74
|
+
* cost as it will be sent.
|
|
75
|
+
*
|
|
63
76
|
* @param {EvmTransaction} tx - The transaction.
|
|
64
77
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
65
78
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
79
|
+
* @throws {Error} If the simulation of the transaction reverts, as an ethers error with code `CALL_EXCEPTION`.
|
|
66
80
|
*/
|
|
67
81
|
quoteSendTransaction(tx: EvmTransaction): Promise<Omit<TransactionResult, "hash">>;
|
|
68
82
|
/**
|
|
69
83
|
* Quotes the costs of a transfer operation.
|
|
70
84
|
*
|
|
71
|
-
* @param {EvmTransferOptions} options - The transfer's options.
|
|
85
|
+
* @param {EvmTransferOptions} options - The transfer's options, including any gas overrides to carry onto the transaction.
|
|
72
86
|
* @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
|
|
73
87
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
74
88
|
*/
|
|
@@ -156,18 +170,31 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
156
170
|
getDelegation(): Promise<DelegationInfo>;
|
|
157
171
|
/** @private */
|
|
158
172
|
private _estimateGasWithAuthList;
|
|
173
|
+
/**
|
|
174
|
+
* Estimates the gas of a transaction by simulating it against the connected provider, using the authorization-list
|
|
175
|
+
* aware estimation for ERC-7702 transactions.
|
|
176
|
+
*
|
|
177
|
+
* @protected
|
|
178
|
+
* @param {EvmTransactionRequest} tx - The transaction to simulate, including its `from` address.
|
|
179
|
+
* @returns {Promise<bigint>} The gas units the simulated transaction consumed.
|
|
180
|
+
*/
|
|
181
|
+
protected _estimateGas(tx: EvmTransactionRequest): Promise<bigint>;
|
|
182
|
+
private _getFeeRate;
|
|
159
183
|
}
|
|
160
184
|
export type Provider = import("ethers").Provider;
|
|
161
185
|
export type Eip1193Provider = import("ethers").Eip1193Provider;
|
|
162
186
|
export type TypedDataDomain = import("ethers").TypedDataDomain;
|
|
163
187
|
export type TypedDataField = import("ethers").TypedDataField;
|
|
188
|
+
export type BlobLike = import("ethers").BlobLike;
|
|
164
189
|
export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
165
190
|
export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
|
|
166
191
|
export type EvmTransactionResponse = import("ethers").TransactionResponse;
|
|
192
|
+
export type EvmTransactionRequest = import("ethers").TransactionRequest;
|
|
167
193
|
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
168
194
|
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
169
195
|
export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
|
|
170
196
|
export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
|
|
197
|
+
export type TransferOptions = import("@tetherto/wdk-wallet").TransferOptions;
|
|
171
198
|
/**
|
|
172
199
|
* The EVM-specific fields added to a normalized transaction receipt.
|
|
173
200
|
*/
|
|
@@ -247,28 +274,31 @@ export type EvmTransaction = {
|
|
|
247
274
|
*/
|
|
248
275
|
chainId?: number | bigint;
|
|
249
276
|
/**
|
|
250
|
-
* -
|
|
277
|
+
* - The maximum price (in wei) per unit of blob gas this transaction will pay for [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) blob data. Required for type 3 (blob) transactions.
|
|
251
278
|
*/
|
|
252
|
-
|
|
253
|
-
};
|
|
254
|
-
export type EvmTransferOptions = {
|
|
279
|
+
maxFeePerBlobGas?: number | bigint;
|
|
255
280
|
/**
|
|
256
|
-
* - The
|
|
281
|
+
* - The blobs of an [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) type 3 transaction.
|
|
257
282
|
*/
|
|
258
|
-
|
|
283
|
+
blobs?: BlobLike[];
|
|
259
284
|
/**
|
|
260
|
-
* - The
|
|
285
|
+
* - The versioned hashes of the blobs of an [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) type 3 transaction.
|
|
261
286
|
*/
|
|
262
|
-
|
|
287
|
+
blobVersionedHashes?: string[];
|
|
263
288
|
/**
|
|
264
|
-
* -
|
|
265
|
-
*/
|
|
266
|
-
amount: number | bigint;
|
|
267
|
-
/**
|
|
268
|
-
* - An optional list of ERC-7702 signed authorizations.
|
|
289
|
+
* - An optional list of ERC-7702 signed authorizations for type 4 transactions.
|
|
269
290
|
*/
|
|
270
291
|
authorizationList?: AuthorizationLike[];
|
|
271
292
|
};
|
|
293
|
+
/**
|
|
294
|
+
* The gas and fee fields of an evm transaction that can be set on transfer and approve options.
|
|
295
|
+
*/
|
|
296
|
+
export type EvmGasOverrides = Pick<EvmTransaction, "gasLimit" | "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas">;
|
|
297
|
+
/**
|
|
298
|
+
* The options of a token transfer, extended with the optional gas overrides and ERC-7702 authorizations of an evm
|
|
299
|
+
* transaction.
|
|
300
|
+
*/
|
|
301
|
+
export type EvmTransferOptions = TransferOptions & EvmGasOverrides & Pick<EvmTransaction, "authorizationList">;
|
|
272
302
|
export type EvmWalletConfig = {
|
|
273
303
|
/**
|
|
274
304
|
* - The url of the rpc provider, or an instance of a class that implements eip-1193. It's also possible to provide an array of urls or EIP 1193 providers instead. In such case, connection errors will cause the wallet to automatically fallback on the next provider in the list.
|
|
@@ -26,7 +26,7 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
26
26
|
* derive child accounts); non-derivable signers (e.g. private-key signers) are not allowed
|
|
27
27
|
* as the default but may be registered by name via {@link addSigner} - If not adding to your global account managment for using just one non derivable signer create a standalone account.
|
|
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
|
+
* @param {string|Uint8Array|ISigner} seedOrSigner - A BIP-39 mnemonic seed phrase, a raw BIP-32 master seed (16-64 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}.
|
|
30
30
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
31
31
|
* @throws {InvalidSignerError} If the default signer doesn't support account derivation.
|
|
32
32
|
*/
|