viem 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/cjs/actions/index.js.map +1 -1
- package/dist/cjs/contract.js.map +1 -1
- package/dist/cjs/errors/abi.js +8 -1
- package/dist/cjs/errors/abi.js.map +1 -1
- package/dist/cjs/errors/contract.js +56 -32
- package/dist/cjs/errors/contract.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/public.js.map +1 -1
- package/dist/cjs/utils/abi/encodePacked.js +2 -0
- package/dist/cjs/utils/abi/encodePacked.js.map +1 -1
- package/dist/cjs/utils/unit/parseUnits.js +2 -1
- package/dist/cjs/utils/unit/parseUnits.js.map +1 -1
- package/dist/esm/actions/index.js.map +1 -1
- package/dist/esm/contract.js.map +1 -1
- package/dist/esm/errors/abi.js +8 -1
- package/dist/esm/errors/abi.js.map +1 -1
- package/dist/esm/errors/contract.js +56 -32
- package/dist/esm/errors/contract.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/public.js.map +1 -1
- package/dist/esm/utils/abi/encodePacked.js +2 -0
- package/dist/esm/utils/abi/encodePacked.js.map +1 -1
- package/dist/esm/utils/unit/parseUnits.js +2 -1
- package/dist/esm/utils/unit/parseUnits.js.map +1 -1
- package/dist/types/actions/index.d.ts +5 -1
- package/dist/types/actions/index.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts +3 -3
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchEvent.d.ts +3 -3
- package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
- package/dist/types/contract.d.ts +5 -1
- package/dist/types/contract.d.ts.map +1 -1
- package/dist/types/errors/abi.d.ts +1 -0
- package/dist/types/errors/abi.d.ts.map +1 -1
- package/dist/types/errors/contract.d.ts +1 -0
- package/dist/types/errors/contract.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +6 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/public.d.ts +5 -1
- package/dist/types/public.d.ts.map +1 -1
- package/dist/types/utils/unit/parseUnits.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/actions/index.ts +6 -2
- package/src/actions/public/watchContractEvent.ts +4 -4
- package/src/actions/public/watchEvent.ts +4 -4
- package/src/contract.ts +6 -2
- package/src/errors/abi.ts +5 -1
- package/src/errors/contract.ts +52 -31
- package/src/errors/version.ts +1 -1
- package/src/index.ts +7 -2
- package/src/public.ts +6 -2
- package/src/utils/abi/encodePacked.ts +1 -0
- package/src/utils/unit/parseUnits.ts +2 -1
package/src/errors/contract.ts
CHANGED
@@ -15,6 +15,7 @@ import { getAbiItem } from '../utils/abi/getAbiItem.js'
|
|
15
15
|
import { formatEther } from '../utils/unit/formatEther.js'
|
16
16
|
import { formatGwei } from '../utils/unit/formatGwei.js'
|
17
17
|
|
18
|
+
import { AbiErrorSignatureNotFoundError } from './abi.js'
|
18
19
|
import { BaseError } from './base.js'
|
19
20
|
import { prettyPrint } from './transaction.js'
|
20
21
|
import { getContractAddress } from './utils.js'
|
@@ -154,6 +155,7 @@ export class ContractFunctionRevertedError extends BaseError {
|
|
154
155
|
|
155
156
|
data?: DecodeErrorResultReturnType
|
156
157
|
reason?: string
|
158
|
+
signature?: Hex
|
157
159
|
|
158
160
|
constructor({
|
159
161
|
abi,
|
@@ -161,56 +163,75 @@ export class ContractFunctionRevertedError extends BaseError {
|
|
161
163
|
functionName,
|
162
164
|
message,
|
163
165
|
}: { abi: Abi; data?: Hex; functionName: string; message?: string }) {
|
166
|
+
let cause: Error | undefined
|
164
167
|
let decodedData: DecodeErrorResultReturnType | undefined = undefined
|
165
168
|
let metaMessages
|
166
169
|
let reason
|
167
170
|
if (data && data !== '0x') {
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
const formattedArgs =
|
180
|
-
abiItem && errorArgs
|
181
|
-
? formatAbiItemWithArgs({
|
182
|
-
abiItem,
|
183
|
-
args: errorArgs,
|
184
|
-
includeFunctionName: false,
|
185
|
-
includeName: false,
|
186
|
-
})
|
171
|
+
try {
|
172
|
+
decodedData = decodeErrorResult({ abi, data })
|
173
|
+
const { abiItem, errorName, args: errorArgs } = decodedData
|
174
|
+
if (errorName === 'Error') {
|
175
|
+
reason = (errorArgs as [string])[0]
|
176
|
+
} else if (errorName === 'Panic') {
|
177
|
+
const [firstArg] = errorArgs as [number]
|
178
|
+
reason = panicReasons[firstArg as keyof typeof panicReasons]
|
179
|
+
} else {
|
180
|
+
const errorWithParams = abiItem
|
181
|
+
? formatAbiItem(abiItem, { includeName: true })
|
187
182
|
: undefined
|
183
|
+
const formattedArgs =
|
184
|
+
abiItem && errorArgs
|
185
|
+
? formatAbiItemWithArgs({
|
186
|
+
abiItem,
|
187
|
+
args: errorArgs,
|
188
|
+
includeFunctionName: false,
|
189
|
+
includeName: false,
|
190
|
+
})
|
191
|
+
: undefined
|
188
192
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
193
|
+
metaMessages = [
|
194
|
+
errorWithParams ? `Error: ${errorWithParams}` : '',
|
195
|
+
formattedArgs && formattedArgs !== '()'
|
196
|
+
? ` ${[...Array(errorName?.length ?? 0).keys()]
|
197
|
+
.map(() => ' ')
|
198
|
+
.join('')}${formattedArgs}`
|
199
|
+
: '',
|
200
|
+
]
|
201
|
+
}
|
202
|
+
} catch (err) {
|
203
|
+
cause = err as Error
|
197
204
|
}
|
198
205
|
} else if (message) reason = message
|
199
206
|
|
207
|
+
let signature: Hex | undefined
|
208
|
+
if (cause instanceof AbiErrorSignatureNotFoundError) {
|
209
|
+
signature = cause.signature
|
210
|
+
metaMessages = [
|
211
|
+
`Unable to decode signature "${signature}" as it was not found on the provided ABI.`,
|
212
|
+
'Make sure you are using the correct ABI and that the error exists on it.',
|
213
|
+
`You can look up the decoded signature here: https://openchain.xyz/signatures?query=${signature}.`,
|
214
|
+
]
|
215
|
+
}
|
216
|
+
|
200
217
|
super(
|
201
|
-
reason && reason !== 'execution reverted'
|
218
|
+
(reason && reason !== 'execution reverted') || signature
|
202
219
|
? [
|
203
|
-
`The contract function "${functionName}" reverted with the following
|
204
|
-
|
220
|
+
`The contract function "${functionName}" reverted with the following ${
|
221
|
+
signature ? 'signature' : 'reason'
|
222
|
+
}:`,
|
223
|
+
reason || signature,
|
205
224
|
].join('\n')
|
206
225
|
: `The contract function "${functionName}" reverted.`,
|
207
226
|
{
|
227
|
+
cause,
|
208
228
|
metaMessages,
|
209
229
|
},
|
210
230
|
)
|
211
231
|
|
212
|
-
this.reason = reason
|
213
232
|
this.data = decodedData
|
233
|
+
this.reason = reason
|
234
|
+
this.signature = signature
|
214
235
|
}
|
215
236
|
}
|
216
237
|
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '1.
|
1
|
+
export const version = '1.4.2'
|
package/src/index.ts
CHANGED
@@ -156,8 +156,12 @@ export type {
|
|
156
156
|
WatchBlockNumberReturnType,
|
157
157
|
} from './actions/public/watchBlockNumber.js'
|
158
158
|
export type {
|
159
|
-
|
160
|
-
|
159
|
+
WatchEventOnLogsFn,
|
160
|
+
/** @deprecated - use `WatchEventOnLogsFn` instead. */
|
161
|
+
WatchEventOnLogsFn as OnLogFn,
|
162
|
+
WatchEventOnLogsParameter,
|
163
|
+
/** @deprecated - use `WatchEventOnLogsParameter` instead. */
|
164
|
+
WatchEventOnLogsParameter as OnLogParameter,
|
161
165
|
WatchEventParameters,
|
162
166
|
WatchEventReturnType,
|
163
167
|
} from './actions/public/watchEvent.js'
|
@@ -233,6 +237,7 @@ export type {
|
|
233
237
|
VerifyHashReturnType,
|
234
238
|
} from './actions/public/verifyHash.js'
|
235
239
|
export type {
|
240
|
+
WatchContractEventOnLogsParameter,
|
236
241
|
WatchContractEventParameters,
|
237
242
|
WatchContractEventReturnType,
|
238
243
|
} from './actions/public/watchContractEvent.js'
|
package/src/public.ts
CHANGED
@@ -114,8 +114,12 @@ export {
|
|
114
114
|
} from './actions/public/watchBlocks.js'
|
115
115
|
export {
|
116
116
|
watchEvent,
|
117
|
-
type
|
118
|
-
|
117
|
+
type WatchEventOnLogsFn,
|
118
|
+
/** @deprecated - use `WatchEventOnLogsFn` instead. */
|
119
|
+
type WatchEventOnLogsFn as OnLogsFn,
|
120
|
+
type WatchEventOnLogsParameter,
|
121
|
+
/** @deprecated - use `WatchEventOnLogsParameter` instead. */
|
122
|
+
type WatchEventOnLogsParameter as OnLogsParameter,
|
119
123
|
} from './actions/public/watchEvent.js'
|
120
124
|
export {
|
121
125
|
watchPendingTransactions,
|
@@ -9,7 +9,8 @@ export function parseUnits(value: string, decimals: number) {
|
|
9
9
|
|
10
10
|
// round off if the fraction is larger than the number of decimals.
|
11
11
|
if (decimals === 0) {
|
12
|
-
|
12
|
+
if (Math.round(Number(`.${fraction}`)) === 1)
|
13
|
+
integer = `${BigInt(integer) + 1n}`
|
13
14
|
fraction = ''
|
14
15
|
} else if (fraction.length > decimals) {
|
15
16
|
const [left, unit, right] = [
|