viem 0.0.0-portable-types-20230518183529 → 0.0.0-portable-types-20230522163654
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/abi/package.json +5 -0
- package/accounts/package.json +5 -0
- package/chains/package.json +5 -0
- package/contract/package.json +5 -0
- package/dist/cjs/actions/ens/getEnsAddress.js +1 -1
- package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/cjs/actions/public/waitForTransactionReceipt.js +23 -12
- package/dist/cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/public/watchBlockNumber.js +2 -1
- package/dist/cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/dist/cjs/actions/public/watchBlocks.js +2 -1
- package/dist/cjs/actions/public/watchBlocks.js.map +1 -1
- package/dist/cjs/actions/public/watchContractEvent.js +2 -1
- package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
- package/dist/cjs/actions/public/watchEvent.js +2 -1
- package/dist/cjs/actions/public/watchEvent.js.map +1 -1
- package/dist/cjs/actions/public/watchPendingTransactions.js +2 -1
- package/dist/cjs/actions/public/watchPendingTransactions.js.map +1 -1
- package/dist/cjs/errors/abi.js +0 -2
- package/dist/cjs/errors/abi.js.map +1 -1
- package/dist/cjs/errors/ccip.js +2 -1
- package/dist/cjs/errors/ccip.js.map +1 -1
- package/dist/cjs/errors/data.js +2 -2
- package/dist/cjs/errors/data.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/utils/abi/decodeAbiParameters.js +22 -14
- package/dist/cjs/utils/abi/decodeAbiParameters.js.map +1 -1
- package/dist/cjs/utils/abi/decodeEventLog.js +5 -5
- package/dist/cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/cjs/utils/data/isHex.js +2 -2
- package/dist/cjs/utils/data/isHex.js.map +1 -1
- package/dist/cjs/utils/data/size.js +1 -1
- package/dist/cjs/utils/data/size.js.map +1 -1
- package/dist/cjs/utils/data/slice.js +36 -12
- package/dist/cjs/utils/data/slice.js.map +1 -1
- package/dist/cjs/utils/data/trim.js +1 -1
- package/dist/cjs/utils/data/trim.js.map +1 -1
- package/dist/cjs/utils/encoding/fromHex.js +2 -2
- package/dist/cjs/utils/encoding/fromHex.js.map +1 -1
- package/dist/cjs/utils/hash/keccak256.js +1 -1
- package/dist/cjs/utils/hash/keccak256.js.map +1 -1
- package/dist/cjs/utils/promise/createBatchScheduler.js.map +1 -1
- package/dist/cjs/utils/rpc.js +49 -40
- package/dist/cjs/utils/rpc.js.map +1 -1
- package/dist/cjs/utils/signature/recoverPublicKey.js +3 -1
- package/dist/cjs/utils/signature/recoverPublicKey.js.map +1 -1
- package/dist/cjs/utils/transaction/serializeTransaction.js +2 -1
- package/dist/cjs/utils/transaction/serializeTransaction.js.map +1 -1
- package/dist/esm/actions/ens/getEnsAddress.js +1 -1
- package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/esm/actions/public/waitForTransactionReceipt.js +23 -12
- package/dist/esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/public/watchBlockNumber.js +2 -1
- package/dist/esm/actions/public/watchBlockNumber.js.map +1 -1
- package/dist/esm/actions/public/watchBlocks.js +2 -1
- package/dist/esm/actions/public/watchBlocks.js.map +1 -1
- package/dist/esm/actions/public/watchContractEvent.js +2 -1
- package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/public/watchEvent.js +2 -1
- package/dist/esm/actions/public/watchEvent.js.map +1 -1
- package/dist/esm/actions/public/watchPendingTransactions.js +2 -1
- package/dist/esm/actions/public/watchPendingTransactions.js.map +1 -1
- package/dist/esm/errors/abi.js +0 -2
- package/dist/esm/errors/abi.js.map +1 -1
- package/dist/esm/errors/ccip.js +2 -1
- package/dist/esm/errors/ccip.js.map +1 -1
- package/dist/esm/errors/data.js +2 -2
- package/dist/esm/errors/data.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/utils/abi/decodeAbiParameters.js +23 -15
- package/dist/esm/utils/abi/decodeAbiParameters.js.map +1 -1
- package/dist/esm/utils/abi/decodeEventLog.js +5 -5
- package/dist/esm/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/esm/utils/data/isHex.js +2 -2
- package/dist/esm/utils/data/isHex.js.map +1 -1
- package/dist/esm/utils/data/size.js +1 -1
- package/dist/esm/utils/data/size.js.map +1 -1
- package/dist/esm/utils/data/slice.js +36 -12
- package/dist/esm/utils/data/slice.js.map +1 -1
- package/dist/esm/utils/data/trim.js +1 -1
- package/dist/esm/utils/data/trim.js.map +1 -1
- package/dist/esm/utils/encoding/fromHex.js +2 -2
- package/dist/esm/utils/encoding/fromHex.js.map +1 -1
- package/dist/esm/utils/hash/keccak256.js +1 -1
- package/dist/esm/utils/hash/keccak256.js.map +1 -1
- package/dist/esm/utils/promise/createBatchScheduler.js.map +1 -1
- package/dist/esm/utils/rpc.js +49 -40
- package/dist/esm/utils/rpc.js.map +1 -1
- package/dist/esm/utils/signature/recoverPublicKey.js +3 -1
- package/dist/esm/utils/signature/recoverPublicKey.js.map +1 -1
- package/dist/esm/utils/transaction/serializeTransaction.js +2 -1
- package/dist/esm/utils/transaction/serializeTransaction.js.map +1 -1
- package/dist/types/actions/public/getTransactionReceipt.d.ts +1 -1
- package/dist/types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/dist/types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/dist/types/actions/public/watchBlocks.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchPendingTransactions.d.ts.map +1 -1
- package/dist/types/clients/createTestClient.d.ts +2 -2
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/errors/abi.d.ts.map +1 -1
- package/dist/types/errors/ccip.d.ts.map +1 -1
- package/dist/types/errors/data.d.ts +2 -1
- package/dist/types/errors/data.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/types/contract.d.ts +7 -33
- package/dist/types/types/contract.d.ts.map +1 -1
- package/dist/types/types/log.d.ts +0 -2
- package/dist/types/types/log.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
- package/dist/types/utils/data/isHex.d.ts +3 -1
- package/dist/types/utils/data/isHex.d.ts.map +1 -1
- package/dist/types/utils/data/slice.d.ts +9 -3
- package/dist/types/utils/data/slice.d.ts.map +1 -1
- package/dist/types/utils/data/trim.d.ts.map +1 -1
- package/dist/types/utils/encoding/fromHex.d.ts +1 -1
- package/dist/types/utils/hash/keccak256.d.ts.map +1 -1
- package/dist/types/utils/promise/createBatchScheduler.d.ts +6 -4
- package/dist/types/utils/promise/createBatchScheduler.d.ts.map +1 -1
- package/dist/types/utils/rpc.d.ts.map +1 -1
- package/dist/types/utils/signature/recoverPublicKey.d.ts.map +1 -1
- package/dist/types/utils/transaction/serializeTransaction.d.ts.map +1 -1
- package/ens/package.json +5 -0
- package/ethers/package.json +5 -0
- package/package.json +13 -2
- package/public/package.json +5 -0
- package/src/actions/ens/getEnsAddress.ts +1 -1
- package/src/actions/public/getTransactionReceipt.ts +1 -1
- package/src/actions/public/waitForTransactionReceipt.ts +33 -11
- package/src/actions/public/watchBlockNumber.ts +2 -1
- package/src/actions/public/watchBlocks.ts +2 -1
- package/src/actions/public/watchContractEvent.ts +2 -1
- package/src/actions/public/watchEvent.ts +2 -1
- package/src/actions/public/watchPendingTransactions.ts +2 -1
- package/src/clients/createTestClient.ts +2 -2
- package/src/errors/abi.ts +0 -2
- package/src/errors/ccip.ts +2 -1
- package/src/errors/data.ts +8 -2
- package/src/errors/version.ts +1 -1
- package/src/types/contract.ts +11 -87
- package/src/types/log.ts +2 -2
- package/src/utils/abi/decodeAbiParameters.ts +36 -15
- package/src/utils/abi/decodeEventLog.ts +5 -5
- package/src/utils/data/isHex.ts +5 -2
- package/src/utils/data/size.ts +1 -1
- package/src/utils/data/slice.ts +43 -11
- package/src/utils/data/trim.ts +3 -1
- package/src/utils/encoding/fromHex.ts +3 -3
- package/src/utils/hash/keccak256.ts +3 -1
- package/src/utils/promise/createBatchScheduler.ts +24 -7
- package/src/utils/rpc.ts +59 -49
- package/src/utils/signature/recoverPublicKey.ts +2 -1
- package/src/utils/transaction/serializeTransaction.ts +3 -2
- package/test/package.json +5 -0
- package/utils/package.json +5 -0
- package/wallet/package.json +5 -0
- package/window/package.json +5 -0
package/package.json
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
"isomorphic-ws": "5.0.0",
|
13
13
|
"ws": "8.12.0"
|
14
14
|
},
|
15
|
-
"version": "0.0.0-portable-types-
|
15
|
+
"version": "0.0.0-portable-types-20230522163654",
|
16
16
|
"files": [
|
17
17
|
"dist",
|
18
18
|
"!dist/**/*.tsbuildinfo",
|
@@ -20,7 +20,18 @@
|
|
20
20
|
"!src/**/*.test.ts",
|
21
21
|
"!src/**/*.test-d.ts",
|
22
22
|
"!src/**/*.bench.ts",
|
23
|
-
"!src/_test/**/*"
|
23
|
+
"!src/_test/**/*",
|
24
|
+
"abi",
|
25
|
+
"accounts",
|
26
|
+
"chains",
|
27
|
+
"contract",
|
28
|
+
"ens",
|
29
|
+
"ethers",
|
30
|
+
"public",
|
31
|
+
"test",
|
32
|
+
"utils",
|
33
|
+
"wallet",
|
34
|
+
"window"
|
24
35
|
],
|
25
36
|
"exports": {
|
26
37
|
".": {
|
@@ -24,7 +24,7 @@ export type GetTransactionReceiptReturnType<
|
|
24
24
|
*
|
25
25
|
* - Docs: https://viem.sh/docs/actions/public/getTransactionReceipt.html
|
26
26
|
* - Example: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/transactions/fetching-transactions
|
27
|
-
* - JSON-RPC Methods: [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#
|
27
|
+
* - JSON-RPC Methods: [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt)
|
28
28
|
*
|
29
29
|
* @param client - Client to use
|
30
30
|
* @param parameters - {@link GetTransactionReceiptParameters}
|
@@ -9,6 +9,8 @@ import type { Chain } from '../../types/chain.js'
|
|
9
9
|
import type { Hash } from '../../types/misc.js'
|
10
10
|
import type { Transaction } from '../../types/transaction.js'
|
11
11
|
import { observe } from '../../utils/observe.js'
|
12
|
+
import { withRetry } from '../../utils/promise/withRetry.js'
|
13
|
+
import { stringify } from '../../utils/stringify.js'
|
12
14
|
|
13
15
|
import { getBlock } from './getBlock.js'
|
14
16
|
import {
|
@@ -106,16 +108,12 @@ export async function waitForTransactionReceipt<
|
|
106
108
|
timeout,
|
107
109
|
}: WaitForTransactionReceiptParameters<TChain>,
|
108
110
|
): Promise<WaitForTransactionReceiptReturnType<TChain>> {
|
109
|
-
const observerId =
|
110
|
-
'waitForTransactionReceipt',
|
111
|
-
client.uid,
|
112
|
-
hash,
|
113
|
-
])
|
111
|
+
const observerId = stringify(['waitForTransactionReceipt', client.uid, hash])
|
114
112
|
|
115
113
|
let transaction: GetTransactionReturnType<TChain> | undefined
|
116
114
|
let replacedTransaction: GetTransactionReturnType<TChain> | undefined
|
117
115
|
let receipt: GetTransactionReceiptReturnType<TChain>
|
118
|
-
let
|
116
|
+
let retrying = false
|
119
117
|
|
120
118
|
return new Promise((resolve, reject) => {
|
121
119
|
if (timeout)
|
@@ -133,7 +131,11 @@ export async function waitForTransactionReceipt<
|
|
133
131
|
emitOnBegin: true,
|
134
132
|
poll: true,
|
135
133
|
pollingInterval,
|
136
|
-
async onBlockNumber(
|
134
|
+
async onBlockNumber(blockNumber_) {
|
135
|
+
if (retrying) return
|
136
|
+
|
137
|
+
let blockNumber = blockNumber_
|
138
|
+
|
137
139
|
const done = async (fn: () => void) => {
|
138
140
|
unwatch()
|
139
141
|
fn()
|
@@ -152,13 +154,34 @@ export async function waitForTransactionReceipt<
|
|
152
154
|
}
|
153
155
|
|
154
156
|
// Get the transaction to check if it's been replaced.
|
155
|
-
|
157
|
+
// We need to retry as some RPC Providers may be slow to sync
|
158
|
+
// up mined transactions.
|
159
|
+
if (!transaction) {
|
160
|
+
retrying = true
|
161
|
+
await withRetry(
|
162
|
+
async () => {
|
163
|
+
transaction = await getTransaction(client, { hash })
|
164
|
+
if (transaction.blockNumber)
|
165
|
+
blockNumber = transaction.blockNumber
|
166
|
+
},
|
167
|
+
{
|
168
|
+
// exponential backoff
|
169
|
+
delay: ({ count }) => ~~(1 << count) * 200,
|
170
|
+
retryCount: 6,
|
171
|
+
},
|
172
|
+
)
|
173
|
+
retrying = false
|
174
|
+
}
|
156
175
|
|
157
176
|
// Get the receipt to check if it's been processed.
|
158
177
|
receipt = await getTransactionReceipt(client, { hash })
|
159
178
|
|
160
179
|
// Check if we have enough confirmations. If not, continue polling.
|
161
|
-
if (
|
180
|
+
if (
|
181
|
+
confirmations > 0 &&
|
182
|
+
blockNumber - receipt.blockNumber + 1n < confirmations
|
183
|
+
)
|
184
|
+
return
|
162
185
|
|
163
186
|
done(() => emit.resolve(receipt))
|
164
187
|
} catch (err) {
|
@@ -220,8 +243,7 @@ export async function waitForTransactionReceipt<
|
|
220
243
|
emit.resolve(receipt)
|
221
244
|
})
|
222
245
|
} else {
|
223
|
-
|
224
|
-
retries++
|
246
|
+
done(() => emit.reject(err))
|
225
247
|
}
|
226
248
|
}
|
227
249
|
},
|
@@ -5,6 +5,7 @@ import type { GetTransportConfig } from '../../types/transport.js'
|
|
5
5
|
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
6
6
|
import { observe } from '../../utils/observe.js'
|
7
7
|
import { poll } from '../../utils/poll.js'
|
8
|
+
import { stringify } from '../../utils/stringify.js'
|
8
9
|
|
9
10
|
import {
|
10
11
|
type GetBlockNumberReturnType,
|
@@ -92,7 +93,7 @@ export function watchBlockNumber<
|
|
92
93
|
let prevBlockNumber: GetBlockNumberReturnType | undefined
|
93
94
|
|
94
95
|
const pollBlockNumber = () => {
|
95
|
-
const observerId =
|
96
|
+
const observerId = stringify([
|
96
97
|
'watchBlockNumber',
|
97
98
|
client.uid,
|
98
99
|
emitOnBegin,
|
@@ -5,6 +5,7 @@ import type { Chain } from '../../types/chain.js'
|
|
5
5
|
import type { GetTransportConfig } from '../../types/transport.js'
|
6
6
|
import { observe } from '../../utils/observe.js'
|
7
7
|
import { poll } from '../../utils/poll.js'
|
8
|
+
import { stringify } from '../../utils/stringify.js'
|
8
9
|
|
9
10
|
import { type GetBlockReturnType, getBlock } from './getBlock.js'
|
10
11
|
|
@@ -100,7 +101,7 @@ export function watchBlocks<
|
|
100
101
|
let prevBlock: GetBlockReturnType<TChain> | undefined
|
101
102
|
|
102
103
|
const pollBlocks = () => {
|
103
|
-
const observerId =
|
104
|
+
const observerId = stringify([
|
104
105
|
'watchBlocks',
|
105
106
|
client.uid,
|
106
107
|
emitMissed,
|
@@ -12,6 +12,7 @@ import {
|
|
12
12
|
} from '../../utils/abi/getAbiItem.js'
|
13
13
|
import { observe } from '../../utils/observe.js'
|
14
14
|
import { poll } from '../../utils/poll.js'
|
15
|
+
import { stringify } from '../../utils/stringify.js'
|
15
16
|
|
16
17
|
import {
|
17
18
|
type CreateContractEventFilterParameters,
|
@@ -103,7 +104,7 @@ export function watchContractEvent<
|
|
103
104
|
pollingInterval = client.pollingInterval,
|
104
105
|
}: WatchContractEventParameters<TAbi, TEventName>,
|
105
106
|
): WatchContractEventReturnType {
|
106
|
-
const observerId =
|
107
|
+
const observerId = stringify([
|
107
108
|
'watchContractEvent',
|
108
109
|
address,
|
109
110
|
args,
|
@@ -11,6 +11,7 @@ import type { Filter } from '../../types/filter.js'
|
|
11
11
|
import type { Log } from '../../types/log.js'
|
12
12
|
import { observe } from '../../utils/observe.js'
|
13
13
|
import { poll } from '../../utils/poll.js'
|
14
|
+
import { stringify } from '../../utils/stringify.js'
|
14
15
|
|
15
16
|
import {
|
16
17
|
type CreateEventFilterParameters,
|
@@ -108,7 +109,7 @@ export function watchEvent<
|
|
108
109
|
pollingInterval = client.pollingInterval,
|
109
110
|
}: WatchEventParameters<TAbiEvent>,
|
110
111
|
): WatchEventReturnType {
|
111
|
-
const observerId =
|
112
|
+
const observerId = stringify([
|
112
113
|
'watchEvent',
|
113
114
|
address,
|
114
115
|
args,
|
@@ -6,6 +6,7 @@ import type { Hash } from '../../types/misc.js'
|
|
6
6
|
import type { GetTransportConfig } from '../../types/transport.js'
|
7
7
|
import { observe } from '../../utils/observe.js'
|
8
8
|
import { poll } from '../../utils/poll.js'
|
9
|
+
import { stringify } from '../../utils/stringify.js'
|
9
10
|
|
10
11
|
import { createPendingTransactionFilter } from './createPendingTransactionFilter.js'
|
11
12
|
import { getFilterChanges } from './getFilterChanges.js'
|
@@ -104,7 +105,7 @@ export function watchPendingTransactions<
|
|
104
105
|
typeof poll_ !== 'undefined' ? poll_ : client.transport.type !== 'webSocket'
|
105
106
|
|
106
107
|
const pollPendingTransactions = () => {
|
107
|
-
const observerId =
|
108
|
+
const observerId = stringify([
|
108
109
|
'watchPendingTransactions',
|
109
110
|
client.uid,
|
110
111
|
batch,
|
@@ -5,7 +5,7 @@ import { type Client, type ClientConfig, createClient } from './createClient.js'
|
|
5
5
|
import { type TestActions, testActions } from './decorators/test.js'
|
6
6
|
import type { Transport } from './transports/createTransport.js'
|
7
7
|
|
8
|
-
export type TestClientMode = 'anvil' | 'hardhat'
|
8
|
+
export type TestClientMode = 'anvil' | 'hardhat' | 'ganache'
|
9
9
|
|
10
10
|
export type TestClientConfig<
|
11
11
|
TMode extends TestClientMode = TestClientMode,
|
@@ -15,7 +15,7 @@ export type TestClientConfig<
|
|
15
15
|
ClientConfig<TTransport, TChain>,
|
16
16
|
'chain' | 'key' | 'name' | 'pollingInterval' | 'transport'
|
17
17
|
> & {
|
18
|
-
/** Mode of the test client. Available: "anvil" | "hardhat" */
|
18
|
+
/** Mode of the test client. Available: "anvil" | "hardhat" | "ganache" */
|
19
19
|
mode: TMode
|
20
20
|
}
|
21
21
|
|
package/src/errors/abi.ts
CHANGED
@@ -293,8 +293,6 @@ export class DecodeLogDataMismatch extends BaseError {
|
|
293
293
|
].join('\n'),
|
294
294
|
{
|
295
295
|
metaMessages: [
|
296
|
-
'This error is usually caused if the ABI event has too many non-indexed event parameters for the emitted log.',
|
297
|
-
'',
|
298
296
|
`Params: (${formatAbiParams(params, { includeName: true })})`,
|
299
297
|
`Data: ${data} (${size} bytes)`,
|
300
298
|
],
|
package/src/errors/ccip.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { Address } from 'abitype'
|
2
2
|
|
3
3
|
import type { Hex } from '../types/misc.js'
|
4
|
+
import { stringify } from '../utils/stringify.js'
|
4
5
|
|
5
6
|
import { BaseError } from './base.js'
|
6
7
|
import { getUrl } from './utils.js'
|
@@ -53,7 +54,7 @@ export class OffchainLookupResponseMalformedError extends BaseError {
|
|
53
54
|
{
|
54
55
|
metaMessages: [
|
55
56
|
`Gateway URL: ${getUrl(url)}`,
|
56
|
-
`Response: ${
|
57
|
+
`Response: ${stringify(result)}`,
|
57
58
|
],
|
58
59
|
},
|
59
60
|
)
|
package/src/errors/data.ts
CHANGED
@@ -2,9 +2,15 @@ import { BaseError } from './base.js'
|
|
2
2
|
|
3
3
|
export class SliceOffsetOutOfBoundsError extends BaseError {
|
4
4
|
override name = 'SliceOffsetOutOfBoundsError'
|
5
|
-
constructor({
|
5
|
+
constructor({
|
6
|
+
offset,
|
7
|
+
position,
|
8
|
+
size,
|
9
|
+
}: { offset: number; position: 'start' | 'end'; size: number }) {
|
6
10
|
super(
|
7
|
-
`Slice
|
11
|
+
`Slice ${
|
12
|
+
position === 'start' ? 'starting' : 'ending'
|
13
|
+
} at offset "${offset}" is out-of-bounds (size: ${size}).`,
|
8
14
|
)
|
9
15
|
}
|
10
16
|
}
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.3.
|
1
|
+
export const version = '0.3.33'
|
package/src/types/contract.ts
CHANGED
@@ -20,7 +20,7 @@ import type {
|
|
20
20
|
|
21
21
|
import type { Hex, LogTopic } from './misc.js'
|
22
22
|
import type { TransactionRequest } from './transaction.js'
|
23
|
-
import type { Filter,
|
23
|
+
import type { Filter, NoUndefined } from './utils.js'
|
24
24
|
|
25
25
|
export type AbiItem = Abi[number]
|
26
26
|
|
@@ -236,7 +236,10 @@ export type GetEventArgsFromTopics<
|
|
236
236
|
TAbiEvent extends AbiEvent & { type: 'event' } = TAbi extends Abi
|
237
237
|
? ExtractAbiEvent<TAbi, TEventName>
|
238
238
|
: AbiEvent & { type: 'event' },
|
239
|
-
TArgs =
|
239
|
+
TArgs = AbiEventParametersToPrimitiveTypes<
|
240
|
+
TAbiEvent['inputs'],
|
241
|
+
{ EnableUnion: false; IndexedOnly: false }
|
242
|
+
>,
|
240
243
|
> = TTopics extends readonly []
|
241
244
|
? TData extends undefined
|
242
245
|
? { args?: never }
|
@@ -249,12 +252,10 @@ export type GetEventArgsFromTopics<
|
|
249
252
|
type EventParameterOptions = {
|
250
253
|
EnableUnion?: boolean
|
251
254
|
IndexedOnly?: boolean
|
252
|
-
Required?: boolean
|
253
255
|
}
|
254
256
|
type DefaultEventParameterOptions = {
|
255
257
|
EnableUnion: true
|
256
258
|
IndexedOnly: true
|
257
|
-
Required: false
|
258
259
|
}
|
259
260
|
|
260
261
|
type HashedEventTypes = 'bytes' | 'string' | 'tuple' | `${string}[${string}]`
|
@@ -326,13 +327,11 @@ export type AbiEventParametersToPrimitiveTypes<
|
|
326
327
|
>
|
327
328
|
},
|
328
329
|
]
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
infer _,
|
335
|
-
]
|
330
|
+
// Distribute over tuple to represent optional parameters
|
331
|
+
| (Filtered extends readonly [
|
332
|
+
...infer Head extends readonly AbiParameter[],
|
333
|
+
infer _,
|
334
|
+
]
|
336
335
|
? AbiEventParametersToPrimitiveTypes<
|
337
336
|
readonly [...{ [K in keyof Head]: Omit<Head[K], 'name'> }],
|
338
337
|
Options
|
@@ -347,81 +346,6 @@ export type AbiEventParametersToPrimitiveTypes<
|
|
347
346
|
? Name
|
348
347
|
: never]?: AbiEventParameterToPrimitiveType<Parameter, Options>
|
349
348
|
} extends infer Mapped
|
350
|
-
?
|
351
|
-
Mapped,
|
352
|
-
Options['Required'] extends boolean ? Options['Required'] : false
|
353
|
-
>
|
349
|
+
? Mapped
|
354
350
|
: never
|
355
351
|
: never
|
356
|
-
|
357
|
-
/**
|
358
|
-
* @internal
|
359
|
-
*/
|
360
|
-
// TODO(@tmm): Simplify this type
|
361
|
-
export type AbiEventTopicsToPrimitiveTypes<
|
362
|
-
TAbiParameters extends readonly AbiParameter[],
|
363
|
-
TTopics extends LogTopic[] | undefined = undefined,
|
364
|
-
TData extends Hex | undefined = undefined,
|
365
|
-
TBase = TAbiParameters[0] extends { name: string } ? {} : [],
|
366
|
-
> = Prettify<
|
367
|
-
TAbiParameters extends readonly [
|
368
|
-
infer Head extends AbiParameter,
|
369
|
-
...infer Tail,
|
370
|
-
]
|
371
|
-
? TTopics extends readonly [infer TopicHead, ...infer TopicTail]
|
372
|
-
? Head extends { indexed: true }
|
373
|
-
? Head extends { name: infer Name extends string }
|
374
|
-
? {
|
375
|
-
[_ in Name]: TopicHead extends LogTopic
|
376
|
-
? AbiEventTopicToPrimitiveType<Head, TopicHead>
|
377
|
-
: never
|
378
|
-
} & (Tail extends readonly []
|
379
|
-
? {}
|
380
|
-
: Tail extends readonly AbiParameter[]
|
381
|
-
? TopicTail extends LogTopic[]
|
382
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, TopicTail, TData>
|
383
|
-
: {}
|
384
|
-
: {})
|
385
|
-
: [
|
386
|
-
TopicHead extends LogTopic
|
387
|
-
? AbiEventTopicToPrimitiveType<Head, TopicHead>
|
388
|
-
: never,
|
389
|
-
...(Tail extends readonly []
|
390
|
-
? []
|
391
|
-
: Tail extends readonly AbiParameter[]
|
392
|
-
? TopicTail extends LogTopic[]
|
393
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, TopicTail, TData>
|
394
|
-
: []
|
395
|
-
: []),
|
396
|
-
]
|
397
|
-
: TBase
|
398
|
-
: TTopics extends readonly []
|
399
|
-
? TData extends '0x'
|
400
|
-
? TBase
|
401
|
-
: TData extends Hex
|
402
|
-
? Head extends AbiParameter
|
403
|
-
? Head extends { indexed: true }
|
404
|
-
? Tail extends readonly AbiParameter[]
|
405
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, [], TData>
|
406
|
-
: TBase
|
407
|
-
: Head extends { name: infer Name extends string }
|
408
|
-
? {
|
409
|
-
[_ in Name]: AbiParameterToPrimitiveType<Head>
|
410
|
-
} & (Tail extends readonly []
|
411
|
-
? {}
|
412
|
-
: Tail extends readonly AbiParameter[]
|
413
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, [], TData>
|
414
|
-
: {})
|
415
|
-
: [
|
416
|
-
AbiParameterToPrimitiveType<Head>,
|
417
|
-
...(Tail extends readonly []
|
418
|
-
? []
|
419
|
-
: Tail extends readonly AbiParameter[]
|
420
|
-
? AbiEventTopicsToPrimitiveTypes<Tail, [], TData>
|
421
|
-
: []),
|
422
|
-
]
|
423
|
-
: TBase
|
424
|
-
: TBase
|
425
|
-
: TBase
|
426
|
-
: undefined
|
427
|
-
>
|
package/src/types/log.ts
CHANGED
@@ -93,7 +93,7 @@ type GetInferredLogValues<
|
|
93
93
|
args: GetEventArgs<
|
94
94
|
TAbi,
|
95
95
|
TEventName,
|
96
|
-
{ EnableUnion: false; IndexedOnly: false
|
96
|
+
{ EnableUnion: false; IndexedOnly: false }
|
97
97
|
>
|
98
98
|
/** The event name decoded from `topics`. */
|
99
99
|
eventName: TEventName
|
@@ -105,7 +105,7 @@ type GetInferredLogValues<
|
|
105
105
|
args: GetEventArgs<
|
106
106
|
TAbi,
|
107
107
|
string,
|
108
|
-
{ EnableUnion: false; IndexedOnly: false
|
108
|
+
{ EnableUnion: false; IndexedOnly: false }
|
109
109
|
>
|
110
110
|
/** The event name decoded from `topics`. */
|
111
111
|
eventName: TName
|
@@ -6,7 +6,6 @@ import type {
|
|
6
6
|
} from 'abitype'
|
7
7
|
|
8
8
|
import {
|
9
|
-
AbiDecodingDataSizeInvalidError,
|
10
9
|
AbiDecodingDataSizeTooSmallError,
|
11
10
|
AbiDecodingZeroDataError,
|
12
11
|
InvalidAbiDecodingTypeError,
|
@@ -38,8 +37,12 @@ export function decodeAbiParameters<
|
|
38
37
|
>(params: Narrow<TParams>, data: Hex): DecodeAbiParametersReturnType<TParams> {
|
39
38
|
if (data === '0x' && (params as unknown[]).length > 0)
|
40
39
|
throw new AbiDecodingZeroDataError()
|
41
|
-
if (size(data)
|
42
|
-
throw new
|
40
|
+
if (size(data) && size(data) < 32)
|
41
|
+
throw new AbiDecodingDataSizeTooSmallError({
|
42
|
+
data,
|
43
|
+
params: params as readonly AbiParameter[],
|
44
|
+
size: size(data),
|
45
|
+
})
|
43
46
|
return decodeParams({
|
44
47
|
data,
|
45
48
|
params: params as readonly AbiParameter[],
|
@@ -102,7 +105,7 @@ function decodeParam({
|
|
102
105
|
return decodeBytes(data, { param, position })
|
103
106
|
}
|
104
107
|
|
105
|
-
const value = slice(data, position, position + 32) as Hex
|
108
|
+
const value = slice(data, position, position + 32, { strict: true }) as Hex
|
106
109
|
if (param.type.startsWith('uint') || param.type.startsWith('int')) {
|
107
110
|
return decodeNumber(value, { param })
|
108
111
|
}
|
@@ -139,9 +142,13 @@ function decodeArray<TParam extends AbiParameter>(
|
|
139
142
|
// we will need to decode the offset of the array data.
|
140
143
|
if (!length) {
|
141
144
|
// Get the offset of the array data.
|
142
|
-
const offset = hexToNumber(
|
145
|
+
const offset = hexToNumber(
|
146
|
+
slice(data, position, position + 32, { strict: true }),
|
147
|
+
)
|
143
148
|
// Get the length of the array from the offset.
|
144
|
-
const length = hexToNumber(
|
149
|
+
const length = hexToNumber(
|
150
|
+
slice(data, offset, offset + 32, { strict: true }),
|
151
|
+
)
|
145
152
|
|
146
153
|
let consumed = 0
|
147
154
|
const value: AbiParameterToPrimitiveType<TParam>[] = []
|
@@ -169,7 +176,9 @@ function decodeArray<TParam extends AbiParameter>(
|
|
169
176
|
let consumed = 0
|
170
177
|
const value: AbiParameterToPrimitiveType<TParam>[] = []
|
171
178
|
for (let i = 0; i < length; ++i) {
|
172
|
-
const offset = hexToNumber(
|
179
|
+
const offset = hexToNumber(
|
180
|
+
slice(data, position, position + 32, { strict: true }),
|
181
|
+
)
|
173
182
|
const decodedChild = decodeParam({
|
174
183
|
data: slice(data, offset),
|
175
184
|
param,
|
@@ -210,15 +219,23 @@ function decodeBytes<TParam extends AbiParameter>(
|
|
210
219
|
if (!size) {
|
211
220
|
// If we don't have a size, we're dealing with a dynamic-size array
|
212
221
|
// so we need to read the offset of the data part first.
|
213
|
-
const offset = hexToNumber(
|
214
|
-
|
222
|
+
const offset = hexToNumber(
|
223
|
+
slice(data, position, position + 32, { strict: true }),
|
224
|
+
)
|
225
|
+
const length = hexToNumber(
|
226
|
+
slice(data, offset, offset + 32, { strict: true }),
|
227
|
+
)
|
215
228
|
// If there is no length, we have zero data.
|
216
229
|
if (length === 0) return { consumed: 32, value: '0x' }
|
217
|
-
const value = slice(data, offset + 32, offset + 32 + length
|
230
|
+
const value = slice(data, offset + 32, offset + 32 + length, {
|
231
|
+
strict: true,
|
232
|
+
})
|
218
233
|
return { consumed: 32, value }
|
219
234
|
}
|
220
235
|
|
221
|
-
const value = slice(data, position, position + parseInt(size)
|
236
|
+
const value = slice(data, position, position + parseInt(size), {
|
237
|
+
strict: true,
|
238
|
+
})
|
222
239
|
return { consumed: 32, value }
|
223
240
|
}
|
224
241
|
|
@@ -238,12 +255,14 @@ function decodeNumber<TParam extends AbiParameter>(
|
|
238
255
|
}
|
239
256
|
|
240
257
|
function decodeString(data: Hex, { position }: { position: number }) {
|
241
|
-
const offset = hexToNumber(
|
242
|
-
|
258
|
+
const offset = hexToNumber(
|
259
|
+
slice(data, position, position + 32, { strict: true }),
|
260
|
+
)
|
261
|
+
const length = hexToNumber(slice(data, offset, offset + 32, { strict: true }))
|
243
262
|
// If there is no length, we have zero data (empty string).
|
244
263
|
if (length === 0) return { consumed: 32, value: '' }
|
245
264
|
const value = hexToString(
|
246
|
-
trim(slice(data, offset + 32, offset + 32 + length)),
|
265
|
+
trim(slice(data, offset + 32, offset + 32 + length, { strict: true })),
|
247
266
|
)
|
248
267
|
return { consumed: 32, value }
|
249
268
|
}
|
@@ -266,7 +285,9 @@ function decodeTuple<
|
|
266
285
|
// If the tuple has a dynamic child, we must first decode the offset to the
|
267
286
|
// tuple data.
|
268
287
|
if (hasDynamicChild(param)) {
|
269
|
-
const offset = hexToNumber(
|
288
|
+
const offset = hexToNumber(
|
289
|
+
slice(data, position, position + 32, { strict: true }),
|
290
|
+
)
|
270
291
|
// Decode each component of the tuple, starting at the offset.
|
271
292
|
for (let i = 0; i < param.components.length; ++i) {
|
272
293
|
const component = param.components[i]
|
@@ -93,8 +93,8 @@ export function decodeEventLog<
|
|
93
93
|
let args: any = isUnnamed ? [] : {}
|
94
94
|
|
95
95
|
// Decode topics (indexed args).
|
96
|
+
const indexedInputs = inputs.filter((x) => 'indexed' in x && x.indexed)
|
96
97
|
if (argTopics.length > 0) {
|
97
|
-
const indexedInputs = inputs.filter((x) => 'indexed' in x && x.indexed)
|
98
98
|
for (let i = 0; i < indexedInputs.length; i++) {
|
99
99
|
const param = indexedInputs[i]
|
100
100
|
const topic = argTopics[i]
|
@@ -108,15 +108,15 @@ export function decodeEventLog<
|
|
108
108
|
}
|
109
109
|
|
110
110
|
// Decode data (non-indexed args).
|
111
|
+
const nonIndexedInputs = inputs.filter((x) => !('indexed' in x && x.indexed))
|
111
112
|
if (data && data !== '0x') {
|
112
|
-
const params = inputs.filter((x) => !('indexed' in x && x.indexed))
|
113
113
|
try {
|
114
|
-
const decodedData = decodeAbiParameters(
|
114
|
+
const decodedData = decodeAbiParameters(nonIndexedInputs, data)
|
115
115
|
if (decodedData) {
|
116
116
|
if (isUnnamed) args = [...args, ...decodedData]
|
117
117
|
else {
|
118
|
-
for (let i = 0; i <
|
119
|
-
args[
|
118
|
+
for (let i = 0; i < nonIndexedInputs.length; i++) {
|
119
|
+
args[nonIndexedInputs[i].name!] = decodedData[i]
|
120
120
|
}
|
121
121
|
}
|
122
122
|
}
|
package/src/utils/data/isHex.ts
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
import type { Hex } from '../../types/misc.js'
|
2
2
|
|
3
|
-
export function isHex(
|
3
|
+
export function isHex(
|
4
|
+
value: unknown,
|
5
|
+
{ strict = true }: { strict?: boolean } = {},
|
6
|
+
): value is Hex {
|
4
7
|
if (!value) return false
|
5
8
|
if (typeof value !== 'string') return false
|
6
|
-
return /^0x[0-9a-fA-F]*$/.test(value)
|
9
|
+
return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith('0x')
|
7
10
|
}
|
package/src/utils/data/size.ts
CHANGED
@@ -9,6 +9,6 @@ import { isHex } from './isHex.js'
|
|
9
9
|
* @returns The size of the value (in bytes).
|
10
10
|
*/
|
11
11
|
export function size(value: Hex | ByteArray) {
|
12
|
-
if (isHex(value)) return Math.ceil((value.length - 2) / 2)
|
12
|
+
if (isHex(value, { strict: false })) return Math.ceil((value.length - 2) / 2)
|
13
13
|
return value.length
|
14
14
|
}
|