Skip to content

Commit

Permalink
add arbitrum decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
luke7211 committed Jan 19, 2024
1 parent dcbb2af commit e016b0c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/optimism-decoder/src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const ctcMapping: Record<string, string | undefined> = {
'0x6F54Ca6F6EdE96662024Ffd61BFd18f3f4e34DFf': 'Zora',
'0xC1B90E1e459aBBDcEc4DCF90dA45ba077d83BFc5': 'PGN',
'0xFF00000000000000000000000000000000000010': 'OPMainnet',
'0x253887577420Cb7e7418cD4d50147743c8041b28': 'Aevo'
'0x253887577420Cb7e7418cD4d50147743c8041b28': 'Aevo',
'0x1c479675ad559DC151F6Ec7ed3FbF8ceE79582B6': 'Arbitrum',
}

const typeMapping: Record<string, string | undefined> = {
Arbitrum: 'Arbitrum',
Lyra: 'OpStack',
Base: 'OpStack',
Zora: 'OpStack',
Expand Down
28 changes: 28 additions & 0 deletions packages/optimism-decoder/src/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@ interface AppendSequencerBatchParams {
transactions: string[] // total_size_bytes[], total_size_bytes[]
}

export async function decodeArbitrumBatch(
kind: string,
data: string,
fourBytesApi: FourBytesApi,
) {
console.log('Decoding Arbitrum...')
const abi = [
'function addSequencerL2BatchFromOrigin(uint256 sequenceNumber,bytes data,uint256 afterDelayedMessagesRead,address gasRefunder,uint256 prevMessageCount,uint256 newMessageCount)',
]
const iface = new ethers.utils.Interface(abi)
const decodedArgs = iface.decodeFunctionData(data.slice(0, 10), data)
console.log(decodedArgs.data.slice(2, 4)) // removing 0x, next byte is type of compressed data
let brotliCompressedData = Buffer.from(data.slice(4), 'hex')
try {
let decompressedData = zlib.brotliDecompressSync(brotliCompressedData, {
//TODO: No idea what are the correct params
params: {
[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_GENERIC,
[zlib.constants.BROTLI_PARAM_QUALITY]:
zlib.constants.BROTLI_MAX_QUALITY,
},
})
console.log('Decompressed data:', decompressedData.toString())
} catch (err) {
console.error('An error occurred:', err)
}
}

export async function decodeOpStackSequencerBatch(
kind: string,
data: string,
Expand Down
6 changes: 4 additions & 2 deletions packages/optimism-decoder/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dotenv from 'dotenv'
import { ethers } from 'ethers'

import { analyzeTransaction } from './analyze'
import { decodeSequencerBatch, decodeOpStackSequencerBatch } from './decode'
import { decodeSequencerBatch, decodeOpStackSequencerBatch, decodeArbitrumBatch } from './decode'
import { FourBytesApi } from './FourBytesApi'

function getEnv(key: string) {
Expand Down Expand Up @@ -46,5 +46,7 @@ export async function run() {
if (kind === 'OpStack') {
await decodeOpStackSequencerBatch(project, data, timestamp, fourBytesApi)
console.log('Batch submission timestamp:', timestamp)
} else await decodeSequencerBatch(project, data, fourBytesApi)
} else if (kind === 'Arbitrum')
await decodeArbitrumBatch(project, data, fourBytesApi)
else await decodeSequencerBatch(project, data, fourBytesApi)
}

0 comments on commit e016b0c

Please sign in to comment.