viem 0.0.0-w-20230821171049 → 0.0.0-w-20230828183856
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 +6 -0
- package/dist/cjs/actions/ens/getEnsAddress.js +2 -2
- package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/cjs/actions/index.js +8 -2
- package/dist/cjs/actions/index.js.map +1 -1
- package/dist/cjs/actions/public/estimateFeesPerGas.js +60 -0
- package/dist/cjs/actions/public/estimateFeesPerGas.js.map +1 -0
- package/dist/cjs/actions/public/estimateGas.js +2 -2
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js +44 -0
- package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -0
- package/dist/cjs/actions/public/verifyHash.js.map +1 -1
- package/dist/cjs/actions/public/verifyMessage.js.map +1 -1
- package/dist/cjs/actions/public/verifyTypedData.js.map +1 -1
- package/dist/cjs/actions/public/waitForTransactionReceipt.js +35 -30
- package/dist/cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/public/watchContractEvent.js +10 -7
- package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
- package/dist/cjs/actions/wallet/deployContract.js.map +1 -1
- package/dist/cjs/actions/wallet/prepareTransactionRequest.js +70 -0
- package/dist/cjs/actions/wallet/prepareTransactionRequest.js.map +1 -0
- package/dist/cjs/actions/wallet/sendRawTransaction.js +11 -0
- package/dist/cjs/actions/wallet/sendRawTransaction.js.map +1 -0
- package/dist/cjs/actions/wallet/sendTransaction.js +6 -6
- package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/cjs/actions/wallet/signTransaction.js +47 -0
- package/dist/cjs/actions/wallet/signTransaction.js.map +1 -0
- package/dist/cjs/chains/celo/formatters.js +4 -1
- package/dist/cjs/chains/celo/formatters.js.map +1 -1
- package/dist/cjs/chains/celo/parsers.js +76 -0
- package/dist/cjs/chains/celo/parsers.js.map +1 -0
- package/dist/cjs/chains/celo/serializers.js +2 -1
- package/dist/cjs/chains/celo/serializers.js.map +1 -1
- package/dist/cjs/chains/index.js +3 -2
- package/dist/cjs/chains/index.js.map +1 -1
- package/dist/cjs/chains/utils.js +3 -1
- package/dist/cjs/chains/utils.js.map +1 -1
- package/dist/cjs/clients/createTestClient.js.map +1 -1
- package/dist/cjs/clients/decorators/public.js +8 -0
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/clients/decorators/wallet.js +6 -0
- package/dist/cjs/clients/decorators/wallet.js.map +1 -1
- package/dist/cjs/errors/fee.js +42 -0
- package/dist/cjs/errors/fee.js.map +1 -0
- package/dist/cjs/index.js +9 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/public.js +5 -1
- package/dist/cjs/public.js.map +1 -1
- package/dist/cjs/utils/data/isBytesEqual.js +4 -3
- package/dist/cjs/utils/data/isBytesEqual.js.map +1 -1
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js +2 -2
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js.map +1 -1
- package/dist/cjs/utils/formatters/transactionRequest.js +9 -1
- package/dist/cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/cjs/utils/index.js +3 -3
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/rpc.js +5 -7
- package/dist/cjs/utils/rpc.js.map +1 -1
- package/dist/cjs/utils/transaction/parseTransaction.js +8 -3
- package/dist/cjs/utils/transaction/parseTransaction.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/actions/ens/getEnsAddress.js +2 -2
- package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/esm/actions/index.js +3 -0
- package/dist/esm/actions/index.js.map +1 -1
- package/dist/esm/actions/public/estimateFeesPerGas.js +78 -0
- package/dist/esm/actions/public/estimateFeesPerGas.js.map +1 -0
- package/dist/esm/actions/public/estimateGas.js +2 -2
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js +64 -0
- package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -0
- package/dist/esm/actions/public/verifyHash.js.map +1 -1
- package/dist/esm/actions/public/verifyMessage.js.map +1 -1
- package/dist/esm/actions/public/verifyTypedData.js.map +1 -1
- package/dist/esm/actions/public/waitForTransactionReceipt.js +39 -34
- package/dist/esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/public/watchContractEvent.js +5 -2
- package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/wallet/deployContract.js.map +1 -1
- package/dist/esm/actions/wallet/prepareTransactionRequest.js +109 -0
- package/dist/esm/actions/wallet/prepareTransactionRequest.js.map +1 -0
- package/dist/esm/actions/wallet/sendRawTransaction.js +31 -0
- package/dist/esm/actions/wallet/sendRawTransaction.js.map +1 -0
- package/dist/esm/actions/wallet/sendTransaction.js +6 -6
- package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/esm/actions/wallet/signTransaction.js +87 -0
- package/dist/esm/actions/wallet/signTransaction.js.map +1 -0
- package/dist/esm/chains/celo/formatters.js +4 -1
- package/dist/esm/chains/celo/formatters.js.map +1 -1
- package/dist/esm/chains/celo/parsers.js +72 -0
- package/dist/esm/chains/celo/parsers.js.map +1 -0
- package/dist/esm/chains/celo/serializers.js +1 -3
- package/dist/esm/chains/celo/serializers.js.map +1 -1
- package/dist/esm/chains/index.js +1 -0
- package/dist/esm/chains/index.js.map +1 -1
- package/dist/esm/chains/utils.js +1 -0
- package/dist/esm/chains/utils.js.map +1 -1
- package/dist/esm/clients/createTestClient.js.map +1 -1
- package/dist/esm/clients/decorators/public.js +8 -0
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/clients/decorators/wallet.js +6 -0
- package/dist/esm/clients/decorators/wallet.js.map +1 -1
- package/dist/esm/errors/fee.js +36 -0
- package/dist/esm/errors/fee.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/public.js +2 -0
- package/dist/esm/public.js.map +1 -1
- package/dist/esm/utils/data/isBytesEqual.js +2 -1
- package/dist/esm/utils/data/isBytesEqual.js.map +1 -1
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js +1 -1
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js.map +1 -1
- package/dist/esm/utils/formatters/transactionRequest.js +8 -0
- package/dist/esm/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/esm/utils/index.js +3 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/rpc.js +5 -7
- package/dist/esm/utils/rpc.js.map +1 -1
- package/dist/esm/utils/transaction/parseTransaction.js +6 -3
- package/dist/esm/utils/transaction/parseTransaction.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/actions/ens/getEnsAddress.d.ts.map +1 -1
- package/dist/types/actions/index.d.ts +3 -0
- package/dist/types/actions/index.d.ts.map +1 -1
- package/dist/types/actions/public/estimateFeesPerGas.d.ts +48 -0
- package/dist/types/actions/public/estimateFeesPerGas.d.ts.map +1 -0
- package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts +37 -0
- package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -0
- package/dist/types/actions/public/verifyHash.d.ts +1 -1
- package/dist/types/actions/public/verifyHash.d.ts.map +1 -1
- package/dist/types/actions/public/verifyMessage.d.ts +2 -2
- package/dist/types/actions/public/verifyMessage.d.ts.map +1 -1
- package/dist/types/actions/public/verifyTypedData.d.ts +2 -2
- package/dist/types/actions/public/verifyTypedData.d.ts.map +1 -1
- package/dist/types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/wallet/deployContract.d.ts +2 -1
- package/dist/types/actions/wallet/deployContract.d.ts.map +1 -1
- package/dist/types/actions/wallet/prepareTransactionRequest.d.ts +52 -0
- package/dist/types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -0
- package/dist/types/actions/wallet/sendRawTransaction.d.ts +38 -0
- package/dist/types/actions/wallet/sendRawTransaction.d.ts.map +1 -0
- package/dist/types/actions/wallet/sendTransaction.d.ts +2 -1
- package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/dist/types/actions/wallet/signTransaction.d.ts +55 -0
- package/dist/types/actions/wallet/signTransaction.d.ts.map +1 -0
- package/dist/types/chains/celo/formatters.d.ts +503 -5
- package/dist/types/chains/celo/formatters.d.ts.map +1 -1
- package/dist/types/chains/celo/parsers.d.ts +6 -0
- package/dist/types/chains/celo/parsers.d.ts.map +1 -0
- package/dist/types/chains/celo/serializers.d.ts +3 -14
- package/dist/types/chains/celo/serializers.d.ts.map +1 -1
- package/dist/types/chains/celo/types.d.ts +54 -14
- package/dist/types/chains/celo/types.d.ts.map +1 -1
- package/dist/types/chains/index.d.ts +15876 -3730
- package/dist/types/chains/index.d.ts.map +1 -1
- package/dist/types/chains/utils.d.ts +3 -2
- package/dist/types/chains/utils.d.ts.map +1 -1
- package/dist/types/clients/createTestClient.d.ts +1 -1
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +112 -0
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/clients/decorators/wallet.d.ts +111 -0
- package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
- package/dist/types/errors/fee.d.ts +16 -0
- package/dist/types/errors/fee.d.ts.map +1 -0
- package/dist/types/index.d.ts +23 -17
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/public.d.ts +2 -0
- package/dist/types/public.d.ts.map +1 -1
- package/dist/types/types/chain.d.ts +64 -11
- package/dist/types/types/chain.d.ts.map +1 -1
- package/dist/types/types/contract.d.ts +2 -2
- package/dist/types/types/contract.d.ts.map +1 -1
- package/dist/types/types/eip1193.d.ts +14 -2
- package/dist/types/types/eip1193.d.ts.map +1 -1
- package/dist/types/types/fee.d.ts +1 -0
- package/dist/types/types/fee.d.ts.map +1 -1
- package/dist/types/utils/chain.d.ts +2 -2
- package/dist/types/utils/chain.d.ts.map +1 -1
- package/dist/types/utils/data/isBytesEqual.d.ts +1 -1
- package/dist/types/utils/data/isBytesEqual.d.ts.map +1 -1
- package/dist/types/utils/ens/encodeLabelhash.d.ts +1 -1
- package/dist/types/utils/ens/encodeLabelhash.d.ts.map +1 -1
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts +1 -1
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionRequest.d.ts +5 -0
- package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +3 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/rpc.d.ts +1 -1
- package/dist/types/utils/rpc.d.ts.map +1 -1
- package/dist/types/utils/transaction/parseTransaction.d.ts +5 -1
- package/dist/types/utils/transaction/parseTransaction.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/actions/ens/getEnsAddress.ts +6 -8
- package/src/actions/index.ts +15 -0
- package/src/actions/public/estimateFeesPerGas.ts +154 -0
- package/src/actions/public/estimateGas.ts +5 -5
- package/src/actions/public/estimateMaxPriorityFeePerGas.ts +98 -0
- package/src/actions/public/verifyHash.ts +1 -1
- package/src/actions/public/verifyMessage.ts +3 -2
- package/src/actions/public/verifyTypedData.ts +3 -2
- package/src/actions/public/waitForTransactionReceipt.ts +48 -44
- package/src/actions/public/watchContractEvent.ts +9 -6
- package/src/actions/wallet/deployContract.ts +2 -1
- package/src/actions/wallet/prepareTransactionRequest.ts +179 -0
- package/src/actions/wallet/sendRawTransaction.ts +48 -0
- package/src/actions/wallet/sendTransaction.ts +8 -7
- package/src/actions/wallet/signTransaction.ts +137 -0
- package/src/chains/celo/formatters.ts +11 -12
- package/src/chains/celo/parsers.ts +123 -0
- package/src/chains/celo/serializers.ts +13 -34
- package/src/chains/celo/types.ts +114 -26
- package/src/chains/index.ts +1 -0
- package/src/chains/utils.ts +10 -6
- package/src/clients/createTestClient.ts +2 -1
- package/src/clients/decorators/public.ts +145 -0
- package/src/clients/decorators/wallet.ts +133 -0
- package/src/errors/fee.ts +27 -0
- package/src/errors/rpc.ts +1 -1
- package/src/index.ts +46 -25
- package/src/public.ts +10 -0
- package/src/types/chain.ts +80 -12
- package/src/types/contract.ts +2 -2
- package/src/types/eip1193.ts +14 -2
- package/src/types/fee.ts +2 -0
- package/src/utils/chain.ts +2 -2
- package/src/utils/data/isBytesEqual.ts +4 -1
- package/src/utils/ens/encodeLabelhash.ts +1 -1
- package/src/utils/ens/encodedLabelToLabelhash.ts +2 -2
- package/src/utils/formatters/transactionRequest.ts +10 -0
- package/src/utils/index.ts +4 -1
- package/src/utils/rpc.ts +5 -8
- package/src/utils/transaction/parseTransaction.ts +7 -9
- package/src/version.ts +1 -1
- package/dist/cjs/utils/transaction/prepareRequest.js +0 -64
- package/dist/cjs/utils/transaction/prepareRequest.js.map +0 -1
- package/dist/esm/utils/transaction/prepareRequest.js +0 -64
- package/dist/esm/utils/transaction/prepareRequest.js.map +0 -1
- package/dist/types/utils/transaction/prepareRequest.d.ts +0 -20
- package/dist/types/utils/transaction/prepareRequest.d.ts.map +0 -1
- package/src/utils/transaction/prepareRequest.ts +0 -143
@@ -1,5 +1,9 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Hex } from '../../types/misc.js';
|
2
|
+
import type { AccessList, TransactionSerializableEIP1559, TransactionSerializableEIP2930, TransactionSerializableLegacy, TransactionSerialized, TransactionType } from '../../types/transaction.js';
|
3
|
+
import type { RecursiveArray } from '../encoding/toRlp.js';
|
2
4
|
import { type GetSerializedTransactionType } from './getSerializedTransactionType.js';
|
3
5
|
export type ParseTransactionReturnType<TSerialized extends TransactionSerialized = TransactionSerialized, TType extends TransactionType = GetSerializedTransactionType<TSerialized>> = (TType extends 'eip1559' ? TransactionSerializableEIP1559 : never) | (TType extends 'eip2930' ? TransactionSerializableEIP2930 : never) | (TType extends 'legacy' ? TransactionSerializableLegacy : never);
|
4
6
|
export declare function parseTransaction<TSerialized extends TransactionSerialized>(serializedTransaction: TSerialized): ParseTransactionReturnType<TSerialized>;
|
7
|
+
export declare function toTransactionArray(serializedTransaction: string): RecursiveArray<`0x${string}`>;
|
8
|
+
export declare function parseAccessList(accessList_: RecursiveArray<Hex>): AccessList;
|
5
9
|
//# sourceMappingURL=parseTransaction.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"parseTransaction.d.ts","sourceRoot":"","sources":["../../../../src/utils/transaction/parseTransaction.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"parseTransaction.d.ts","sourceRoot":"","sources":["../../../../src/utils/transaction/parseTransaction.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAa,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EACV,UAAU,EAGV,8BAA8B,EAC9B,8BAA8B,EAC9B,6BAA6B,EAC7B,qBAAqB,EAGrB,eAAe,EAChB,MAAM,4BAA4B,CAAA;AAOnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAQ1D,OAAO,EACL,KAAK,4BAA4B,EAElC,MAAM,mCAAmC,CAAA;AAE1C,MAAM,MAAM,0BAA0B,CACpC,WAAW,SAAS,qBAAqB,GAAG,qBAAqB,EACjE,KAAK,SAAS,eAAe,GAAG,4BAA4B,CAAC,WAAW,CAAC,IAEvE,CAAC,KAAK,SAAS,SAAS,GAAG,8BAA8B,GAAG,KAAK,CAAC,GAClE,CAAC,KAAK,SAAS,SAAS,GAAG,8BAA8B,GAAG,KAAK,CAAC,GAClE,CAAC,KAAK,SAAS,QAAQ,GAAG,6BAA6B,GAAG,KAAK,CAAC,CAAA;AAEpE,wBAAgB,gBAAgB,CAAC,WAAW,SAAS,qBAAqB,EACxE,qBAAqB,EAAE,WAAW,GACjC,0BAA0B,CAAC,WAAW,CAAC,CAgBzC;AAoMD,wBAAgB,kBAAkB,CAAC,qBAAqB,EAAE,MAAM,iCAE/D;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,UAAU,CAa5E"}
|
package/dist/types/version.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const version = "1.
|
1
|
+
export declare const version = "1.8.1";
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
@@ -106,14 +106,12 @@ export async function getEnsAddress<TChain extends Chain | undefined,>(
|
|
106
106
|
|
107
107
|
if (res[0] === '0x') return null
|
108
108
|
|
109
|
-
const address =
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}),
|
116
|
-
)
|
109
|
+
const address = decodeFunctionResult({
|
110
|
+
abi: addressResolverAbi,
|
111
|
+
args: coinType != null ? [namehash(name), BigInt(coinType)] : undefined,
|
112
|
+
functionName: 'addr',
|
113
|
+
data: res[0],
|
114
|
+
})
|
117
115
|
|
118
116
|
if (address === '0x') return null
|
119
117
|
if (trim(address) === '0x00') return null
|
package/src/actions/index.ts
CHANGED
@@ -224,11 +224,26 @@ export {
|
|
224
224
|
} from './test/inspectTxpool.js'
|
225
225
|
export { type ResetParameters, reset } from './test/reset.js'
|
226
226
|
export { type RevertParameters, revert } from './test/revert.js'
|
227
|
+
export {
|
228
|
+
type PrepareTransactionRequestParameters,
|
229
|
+
type PrepareTransactionRequestReturnType,
|
230
|
+
prepareTransactionRequest,
|
231
|
+
} from './wallet/prepareTransactionRequest.js'
|
227
232
|
export {
|
228
233
|
type SendTransactionParameters,
|
229
234
|
type SendTransactionReturnType,
|
230
235
|
sendTransaction,
|
231
236
|
} from './wallet/sendTransaction.js'
|
237
|
+
export {
|
238
|
+
type SignTransactionParameters,
|
239
|
+
type SignTransactionReturnType,
|
240
|
+
signTransaction,
|
241
|
+
} from './wallet/signTransaction.js'
|
242
|
+
export {
|
243
|
+
type SendRawTransactionParameters,
|
244
|
+
type SendRawTransactionReturnType,
|
245
|
+
sendRawTransaction,
|
246
|
+
} from './wallet/sendRawTransaction.js'
|
232
247
|
export {
|
233
248
|
type SendUnsignedTransactionParameters,
|
234
249
|
type SendUnsignedTransactionReturnType,
|
@@ -0,0 +1,154 @@
|
|
1
|
+
import type { Client } from '../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
3
|
+
import {
|
4
|
+
BaseFeeScalarError,
|
5
|
+
Eip1559FeesNotSupportedError,
|
6
|
+
} from '../../errors/fee.js'
|
7
|
+
import type { Block } from '../../types/block.js'
|
8
|
+
import type {
|
9
|
+
Chain,
|
10
|
+
ChainEstimateFeesPerGasFnParameters,
|
11
|
+
ChainFeesFnParameters,
|
12
|
+
} from '../../types/chain.js'
|
13
|
+
import type { GetChain } from '../../types/chain.js'
|
14
|
+
import type {
|
15
|
+
FeeValuesEIP1559,
|
16
|
+
FeeValuesLegacy,
|
17
|
+
FeeValuesType,
|
18
|
+
} from '../../types/fee.js'
|
19
|
+
import type { PrepareTransactionRequestParameters } from '../wallet/prepareTransactionRequest.js'
|
20
|
+
import { internal_estimateMaxPriorityFeePerGas } from './estimateMaxPriorityFeePerGas.js'
|
21
|
+
import { getBlock } from './getBlock.js'
|
22
|
+
import { getGasPrice } from './getGasPrice.js'
|
23
|
+
|
24
|
+
export type EstimateFeesPerGasParameters<
|
25
|
+
chain extends Chain | undefined = Chain | undefined,
|
26
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
27
|
+
type extends FeeValuesType = FeeValuesType,
|
28
|
+
> = {
|
29
|
+
/**
|
30
|
+
* The type of fee values to return.
|
31
|
+
*
|
32
|
+
* - `legacy`: Returns the legacy gas price.
|
33
|
+
* - `eip1559`: Returns the max fee per gas and max priority fee per gas.
|
34
|
+
*
|
35
|
+
* @default 'eip1559'
|
36
|
+
*/
|
37
|
+
type?: type | FeeValuesType
|
38
|
+
} & GetChain<chain, chainOverride>
|
39
|
+
|
40
|
+
export type EstimateFeesPerGasReturnType<
|
41
|
+
type extends FeeValuesType = FeeValuesType,
|
42
|
+
> =
|
43
|
+
| (type extends 'legacy' ? FeeValuesLegacy : never)
|
44
|
+
| (type extends 'eip1559' ? FeeValuesEIP1559 : never)
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Returns an estimate for the fees per gas (in wei) for a
|
48
|
+
* transaction to be likely included in the next block.
|
49
|
+
* Defaults to [`chain.fees.estimateFeesPerGas`](/docs/clients/chains.html#fees-estimatefeespergas) if set.
|
50
|
+
*
|
51
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateFeesPerGas.html
|
52
|
+
*
|
53
|
+
* @param client - Client to use
|
54
|
+
* @param parameters - {@link EstimateFeesPerGasParameters}
|
55
|
+
* @returns An estimate (in wei) for the fees per gas. {@link EstimateFeesPerGasReturnType}
|
56
|
+
*
|
57
|
+
* @example
|
58
|
+
* import { createPublicClient, http } from 'viem'
|
59
|
+
* import { mainnet } from 'viem/chains'
|
60
|
+
* import { estimateFeesPerGas } from 'viem/actions'
|
61
|
+
*
|
62
|
+
* const client = createPublicClient({
|
63
|
+
* chain: mainnet,
|
64
|
+
* transport: http(),
|
65
|
+
* })
|
66
|
+
* const maxPriorityFeePerGas = await estimateFeesPerGas(client)
|
67
|
+
* // { maxFeePerGas: ..., maxPriorityFeePerGas: ... }
|
68
|
+
*/
|
69
|
+
export async function estimateFeesPerGas<
|
70
|
+
chain extends Chain | undefined,
|
71
|
+
chainOverride extends Chain | undefined,
|
72
|
+
type extends FeeValuesType = 'eip1559',
|
73
|
+
>(
|
74
|
+
client: Client<Transport, chain>,
|
75
|
+
args?: EstimateFeesPerGasParameters<chain, chainOverride, type>,
|
76
|
+
): Promise<EstimateFeesPerGasReturnType<type>> {
|
77
|
+
return internal_estimateFeesPerGas(client, args as any)
|
78
|
+
}
|
79
|
+
|
80
|
+
export async function internal_estimateFeesPerGas<
|
81
|
+
chain extends Chain | undefined,
|
82
|
+
chainOverride extends Chain | undefined,
|
83
|
+
type extends FeeValuesType = 'eip1559',
|
84
|
+
>(
|
85
|
+
client: Client<Transport, chain>,
|
86
|
+
args: EstimateFeesPerGasParameters<chain, chainOverride, type> & {
|
87
|
+
block?: Block
|
88
|
+
request?: PrepareTransactionRequestParameters
|
89
|
+
},
|
90
|
+
): Promise<EstimateFeesPerGasReturnType<type>> {
|
91
|
+
const {
|
92
|
+
block: block_,
|
93
|
+
chain = client.chain,
|
94
|
+
request,
|
95
|
+
type = 'eip1559',
|
96
|
+
} = args || {}
|
97
|
+
|
98
|
+
const baseFeeMultiplier = await (async () => {
|
99
|
+
if (typeof chain?.fees?.baseFeeMultiplier === 'function')
|
100
|
+
return chain.fees.baseFeeMultiplier({
|
101
|
+
block: block_ as Block,
|
102
|
+
client,
|
103
|
+
request,
|
104
|
+
} as ChainFeesFnParameters)
|
105
|
+
return chain?.fees?.baseFeeMultiplier ?? 1.2
|
106
|
+
})()
|
107
|
+
if (baseFeeMultiplier < 1) throw new BaseFeeScalarError()
|
108
|
+
|
109
|
+
const decimals = baseFeeMultiplier.toString().split('.')[1].length
|
110
|
+
const denominator = 10 ** decimals
|
111
|
+
const multiply = (base: bigint) =>
|
112
|
+
(base * BigInt(baseFeeMultiplier * denominator)) / BigInt(denominator)
|
113
|
+
|
114
|
+
const block = block_ ? block_ : await getBlock(client)
|
115
|
+
|
116
|
+
if (typeof chain?.fees?.estimateFeesPerGas === 'function')
|
117
|
+
return chain.fees.estimateFeesPerGas({
|
118
|
+
block: block_ as Block,
|
119
|
+
client,
|
120
|
+
multiply,
|
121
|
+
request,
|
122
|
+
type,
|
123
|
+
} as ChainEstimateFeesPerGasFnParameters) as unknown as EstimateFeesPerGasReturnType<type>
|
124
|
+
|
125
|
+
if (type === 'eip1559') {
|
126
|
+
if (typeof block.baseFeePerGas !== 'bigint')
|
127
|
+
throw new Eip1559FeesNotSupportedError()
|
128
|
+
|
129
|
+
const maxPriorityFeePerGas = request?.maxPriorityFeePerGas
|
130
|
+
? request.maxPriorityFeePerGas
|
131
|
+
: await internal_estimateMaxPriorityFeePerGas(
|
132
|
+
client as Client<Transport, Chain>,
|
133
|
+
{
|
134
|
+
block,
|
135
|
+
chain,
|
136
|
+
request,
|
137
|
+
},
|
138
|
+
)
|
139
|
+
|
140
|
+
const baseFeePerGas = multiply(block.baseFeePerGas)
|
141
|
+
const maxFeePerGas =
|
142
|
+
request?.maxFeePerGas ?? baseFeePerGas + maxPriorityFeePerGas
|
143
|
+
|
144
|
+
return {
|
145
|
+
maxFeePerGas,
|
146
|
+
maxPriorityFeePerGas,
|
147
|
+
} as EstimateFeesPerGasReturnType<type>
|
148
|
+
}
|
149
|
+
|
150
|
+
const gasPrice = request?.gasPrice ?? multiply(await getGasPrice(client))
|
151
|
+
return {
|
152
|
+
gasPrice,
|
153
|
+
} as EstimateFeesPerGasReturnType<type>
|
154
|
+
}
|
@@ -21,9 +21,9 @@ import {
|
|
21
21
|
assertRequest,
|
22
22
|
} from '../../utils/transaction/assertRequest.js'
|
23
23
|
import {
|
24
|
-
type
|
25
|
-
|
26
|
-
} from '
|
24
|
+
type PrepareTransactionRequestParameters,
|
25
|
+
prepareTransactionRequest,
|
26
|
+
} from '../wallet/prepareTransactionRequest.js'
|
27
27
|
|
28
28
|
export type FormattedEstimateGas<
|
29
29
|
TChain extends Chain | undefined = Chain | undefined,
|
@@ -107,9 +107,9 @@ export async function estimateGas<
|
|
107
107
|
...rest
|
108
108
|
} =
|
109
109
|
account.type === 'local'
|
110
|
-
? ((await
|
110
|
+
? ((await prepareTransactionRequest(
|
111
111
|
client,
|
112
|
-
args as
|
112
|
+
args as PrepareTransactionRequestParameters,
|
113
113
|
)) as EstimateGasParameters)
|
114
114
|
: args
|
115
115
|
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import type { Client } from '../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
3
|
+
import { Eip1559FeesNotSupportedError } from '../../errors/fee.js'
|
4
|
+
import type { Account } from '../../types/account.js'
|
5
|
+
import type { Block } from '../../types/block.js'
|
6
|
+
import type { Chain, ChainFeesFnParameters } from '../../types/chain.js'
|
7
|
+
import type { GetChain } from '../../types/chain.js'
|
8
|
+
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
9
|
+
import type { PrepareTransactionRequestParameters } from '../wallet/prepareTransactionRequest.js'
|
10
|
+
import { getBlock } from './getBlock.js'
|
11
|
+
import { getGasPrice } from './getGasPrice.js'
|
12
|
+
|
13
|
+
export type EstimateMaxPriorityFeePerGasParameters<
|
14
|
+
chain extends Chain | undefined = Chain | undefined,
|
15
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
16
|
+
> = GetChain<chain, chainOverride>
|
17
|
+
export type EstimateMaxPriorityFeePerGasReturnType = bigint
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Returns an estimate for the max priority fee per gas (in wei) for a
|
21
|
+
* transaction to be likely included in the next block.
|
22
|
+
* Defaults to [`chain.fees.defaultPriorityFee`](/docs/clients/chains.html#fees-defaultpriorityfee) if set.
|
23
|
+
*
|
24
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateMaxPriorityFeePerGas.html
|
25
|
+
*
|
26
|
+
* @param client - Client to use
|
27
|
+
* @returns An estimate (in wei) for the max priority fee per gas. {@link EstimateMaxPriorityFeePerGasReturnType}
|
28
|
+
*
|
29
|
+
* @example
|
30
|
+
* import { createPublicClient, http } from 'viem'
|
31
|
+
* import { mainnet } from 'viem/chains'
|
32
|
+
* import { estimateMaxPriorityFeePerGas } from 'viem/actions'
|
33
|
+
*
|
34
|
+
* const client = createPublicClient({
|
35
|
+
* chain: mainnet,
|
36
|
+
* transport: http(),
|
37
|
+
* })
|
38
|
+
* const maxPriorityFeePerGas = await estimateMaxPriorityFeePerGas(client)
|
39
|
+
* // 10000000n
|
40
|
+
*/
|
41
|
+
export async function estimateMaxPriorityFeePerGas<
|
42
|
+
chain extends Chain | undefined,
|
43
|
+
chainOverride extends Chain | undefined,
|
44
|
+
>(
|
45
|
+
client: Client<Transport, chain>,
|
46
|
+
args?: EstimateMaxPriorityFeePerGasParameters<chain, chainOverride>,
|
47
|
+
): Promise<EstimateMaxPriorityFeePerGasReturnType> {
|
48
|
+
return internal_estimateMaxPriorityFeePerGas(client, args as any)
|
49
|
+
}
|
50
|
+
|
51
|
+
export async function internal_estimateMaxPriorityFeePerGas<
|
52
|
+
chain extends Chain | undefined,
|
53
|
+
chainOverride extends Chain | undefined,
|
54
|
+
>(
|
55
|
+
client: Client<Transport, chain>,
|
56
|
+
args: EstimateMaxPriorityFeePerGasParameters<chain, chainOverride> & {
|
57
|
+
block?: Block
|
58
|
+
request?: PrepareTransactionRequestParameters<
|
59
|
+
chain,
|
60
|
+
Account | undefined,
|
61
|
+
chainOverride
|
62
|
+
>
|
63
|
+
},
|
64
|
+
): Promise<EstimateMaxPriorityFeePerGasReturnType> {
|
65
|
+
const { block: block_, chain = client.chain, request } = args || {}
|
66
|
+
if (typeof chain?.fees?.defaultPriorityFee === 'function') {
|
67
|
+
const block = block_ || (await getBlock(client))
|
68
|
+
return chain.fees.defaultPriorityFee({
|
69
|
+
block,
|
70
|
+
client,
|
71
|
+
request,
|
72
|
+
} as ChainFeesFnParameters)
|
73
|
+
} else if (chain?.fees?.defaultPriorityFee)
|
74
|
+
return chain?.fees?.defaultPriorityFee
|
75
|
+
|
76
|
+
try {
|
77
|
+
const maxPriorityFeePerGasHex = await client.request({
|
78
|
+
method: 'eth_maxPriorityFeePerGas',
|
79
|
+
})
|
80
|
+
return hexToBigInt(maxPriorityFeePerGasHex)
|
81
|
+
} catch {
|
82
|
+
// If the RPC Provider does not support `eth_maxPriorityFeePerGas`
|
83
|
+
// fall back to calculating it manually via `gasPrice - baseFeePerGas`.
|
84
|
+
// See: https://github.com/ethereum/pm/issues/328#:~:text=eth_maxPriorityFeePerGas%20after%20London%20will%20effectively%20return%20eth_gasPrice%20%2D%20baseFee
|
85
|
+
const [block, gasPrice] = await Promise.all([
|
86
|
+
block_ ? Promise.resolve(block_) : getBlock(client),
|
87
|
+
getGasPrice(client),
|
88
|
+
])
|
89
|
+
|
90
|
+
if (typeof block.baseFeePerGas !== 'bigint')
|
91
|
+
throw new Eip1559FeesNotSupportedError()
|
92
|
+
|
93
|
+
const maxPriorityFeePerGas = gasPrice - block.baseFeePerGas
|
94
|
+
|
95
|
+
if (maxPriorityFeePerGas < 0n) return 0n
|
96
|
+
return maxPriorityFeePerGas
|
97
|
+
}
|
98
|
+
}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import type { Address } from 'abitype'
|
2
2
|
|
3
|
-
import type { Chain } from '../../chains/index.js'
|
4
3
|
import type { Client } from '../../clients/createClient.js'
|
5
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
6
5
|
import { universalSignatureValidatorAbi } from '../../constants/abis.js'
|
7
6
|
import { universalSignatureValidatorByteCode } from '../../constants/contracts.js'
|
8
7
|
import { CallExecutionError } from '../../errors/contract.js'
|
8
|
+
import type { Chain } from '../../types/chain.js'
|
9
9
|
import type { ByteArray, Hex } from '../../types/misc.js'
|
10
10
|
import { isBytesEqual } from '../../utils/data/isBytesEqual.js'
|
11
11
|
import { encodeDeployData, isHex, toHex } from '../../utils/index.js'
|
@@ -1,10 +1,11 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
|
2
3
|
import type { Client } from '../../clients/createClient.js'
|
3
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import type { Chain } from '../../types/chain.js'
|
4
6
|
import type { ByteArray, Hex, SignableMessage } from '../../types/misc.js'
|
5
7
|
import { hashMessage } from '../../utils/index.js'
|
6
8
|
import { type VerifyHashParameters, verifyHash } from './verifyHash.js'
|
7
|
-
import type { Address } from 'abitype'
|
8
9
|
|
9
10
|
export type VerifyMessageParameters = Omit<VerifyHashParameters, 'hash'> & {
|
10
11
|
/** The address that signed the original message. */
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Address, TypedData } from 'abitype'
|
2
|
+
|
2
3
|
import type { Client } from '../../clients/createClient.js'
|
3
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import type { Chain } from '../../types/chain.js'
|
4
6
|
import type { ByteArray, Hex } from '../../types/misc.js'
|
5
7
|
import type { TypedDataDefinition } from '../../types/typedData.js'
|
6
8
|
import { hashTypedData } from '../../utils/signature/hashTypedData.js'
|
7
9
|
import { type VerifyHashParameters, verifyHash } from './verifyHash.js'
|
8
|
-
import type { Address, TypedData } from 'abitype'
|
9
10
|
|
10
11
|
export type VerifyTypedDataParameters<
|
11
12
|
TTypedData extends TypedData | { [key: string]: unknown } = TypedData,
|
@@ -192,56 +192,60 @@ export async function waitForTransactionReceipt<
|
|
192
192
|
(err instanceof TransactionNotFoundError ||
|
193
193
|
err instanceof TransactionReceiptNotFoundError)
|
194
194
|
) {
|
195
|
-
|
196
|
-
|
197
|
-
// Let's retrieve the transactions from the current block.
|
198
|
-
const block = await getBlock(client, {
|
199
|
-
blockNumber,
|
200
|
-
includeTransactions: true,
|
201
|
-
})
|
202
|
-
|
203
|
-
const replacementTransaction = (
|
204
|
-
block.transactions as Transaction[]
|
205
|
-
).find(
|
206
|
-
({ from, nonce }) =>
|
207
|
-
from === replacedTransaction!.from &&
|
208
|
-
nonce === replacedTransaction!.nonce,
|
209
|
-
)
|
195
|
+
try {
|
196
|
+
replacedTransaction = transaction
|
210
197
|
|
211
|
-
|
212
|
-
|
198
|
+
// Let's retrieve the transactions from the current block.
|
199
|
+
const block = await getBlock(client, {
|
200
|
+
blockNumber,
|
201
|
+
includeTransactions: true,
|
202
|
+
})
|
213
203
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
204
|
+
const replacementTransaction = (
|
205
|
+
block.transactions as Transaction[]
|
206
|
+
).find(
|
207
|
+
({ from, nonce }) =>
|
208
|
+
from === replacedTransaction!.from &&
|
209
|
+
nonce === replacedTransaction!.nonce,
|
210
|
+
)
|
218
211
|
|
219
|
-
|
220
|
-
|
221
|
-
return
|
212
|
+
// If we couldn't find a replacement transaction, continue polling.
|
213
|
+
if (!replacementTransaction) return
|
222
214
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
replacementTransaction.value === 0n
|
232
|
-
) {
|
233
|
-
reason = 'cancelled'
|
234
|
-
}
|
215
|
+
// If we found a replacement transaction, return it's receipt.
|
216
|
+
receipt = await getTransactionReceipt(client, {
|
217
|
+
hash: replacementTransaction.hash,
|
218
|
+
})
|
219
|
+
|
220
|
+
// Check if we have enough confirmations. If not, continue polling.
|
221
|
+
if (blockNumber - receipt.blockNumber + 1n < confirmations)
|
222
|
+
return
|
235
223
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
224
|
+
let reason: ReplacementReason = 'replaced'
|
225
|
+
if (
|
226
|
+
replacementTransaction.to === replacedTransaction.to &&
|
227
|
+
replacementTransaction.value === replacedTransaction.value
|
228
|
+
) {
|
229
|
+
reason = 'repriced'
|
230
|
+
} else if (
|
231
|
+
replacementTransaction.from === replacementTransaction.to &&
|
232
|
+
replacementTransaction.value === 0n
|
233
|
+
) {
|
234
|
+
reason = 'cancelled'
|
235
|
+
}
|
236
|
+
|
237
|
+
done(() => {
|
238
|
+
emit.onReplaced?.({
|
239
|
+
reason,
|
240
|
+
replacedTransaction: replacedTransaction!,
|
241
|
+
transaction: replacementTransaction,
|
242
|
+
transactionReceipt: receipt,
|
243
|
+
})
|
244
|
+
emit.resolve(receipt)
|
242
245
|
})
|
243
|
-
|
244
|
-
|
246
|
+
} catch (err_) {
|
247
|
+
done(() => emit.reject(err_))
|
248
|
+
}
|
245
249
|
} else {
|
246
250
|
done(() => emit.reject(err))
|
247
251
|
}
|
@@ -2,7 +2,6 @@ import type { Abi, AbiEvent, Address, ExtractAbiEvent } from 'abitype'
|
|
2
2
|
|
3
3
|
import type { Client } from '../../clients/createClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
-
import type { EncodeEventTopicsParameters, LogTopic } from '../../index.js'
|
6
5
|
import type { Chain } from '../../types/chain.js'
|
7
6
|
import type { GetEventArgs, InferEventName } from '../../types/contract.js'
|
8
7
|
import type { Filter } from '../../types/filter.js'
|
@@ -17,14 +16,18 @@ import { observe } from '../../utils/observe.js'
|
|
17
16
|
import { poll } from '../../utils/poll.js'
|
18
17
|
import { stringify } from '../../utils/stringify.js'
|
19
18
|
|
20
|
-
import { DecodeLogDataMismatch } from '../../errors/abi.js'
|
21
19
|
import {
|
20
|
+
DecodeLogDataMismatch,
|
22
21
|
DecodeLogTopicsMismatch,
|
23
|
-
|
24
|
-
|
22
|
+
} from '../../errors/abi.js'
|
23
|
+
import { InvalidInputRpcError } from '../../errors/rpc.js'
|
24
|
+
import type { LogTopic } from '../../types/misc.js'
|
25
|
+
import { decodeEventLog } from '../../utils/abi/decodeEventLog.js'
|
26
|
+
import {
|
27
|
+
type EncodeEventTopicsParameters,
|
25
28
|
encodeEventTopics,
|
26
|
-
|
27
|
-
} from '../../
|
29
|
+
} from '../../utils/abi/encodeEventTopics.js'
|
30
|
+
import { formatLog } from '../../utils/formatters/log.js'
|
28
31
|
import {
|
29
32
|
type CreateContractEventFilterParameters,
|
30
33
|
createContractEventFilter,
|
@@ -3,7 +3,8 @@ import type { Abi } from 'abitype'
|
|
3
3
|
import type { Account } from '../../accounts/types.js'
|
4
4
|
import type { Client } from '../../clients/createClient.js'
|
5
5
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
6
|
-
import type { Chain
|
6
|
+
import type { Chain } from '../../types/chain.js'
|
7
|
+
import type { GetChain } from '../../types/chain.js'
|
7
8
|
import type { GetConstructorArgs } from '../../types/contract.js'
|
8
9
|
import type { Hex } from '../../types/misc.js'
|
9
10
|
import type { UnionOmit } from '../../types/utils.js'
|