1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
export const encodeRevertData = (
flag: number,
data: string = '0x',
nuisanceGasLeft: number = 0,
ovmGasRefund: number = 0
): string => {
const abiEncoded: string = ethers.utils.defaultAbiCoder.encode(
['uint256', 'uint256', 'uint256', 'bytes'],
[flag, nuisanceGasLeft, ovmGasRefund, data]
)
return abiEncoded
}
export const decodeRevertData = (revertData: string): any => {
const decoded = ethers.utils.defaultAbiCoder.decode(
['uint256', 'uint256', 'uint256', 'bytes'],
revertData
)
return (
'[revertFlag:' +
Object.keys(REVERT_FLAGS)[decoded[0]] +
', nuisanceGasLeft:' +
decoded[1] +
', ovmGasRefund: ' +
decoded[2] +
', data: ' +
decoded[3] +
']'
)
}
export const REVERT_FLAGS = {
DID_NOT_REVERT: 0,
OUT_OF_GAS: 1,
INTENTIONAL_REVERT: 2,
EXCEEDS_NUISANCE_GAS: 3,
INVALID_STATE_ACCESS: 4,
UNSAFE_BYTECODE: 5,
CREATE_COLLISION: 6,
STATIC_VIOLATION: 7,
CREATE_EXCEPTION: 8,
}