Skip to content

Commit

Permalink
fix: zksync formatters (wevm#1448)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom authored Nov 5, 2023
1 parent b02b88b commit c2fab4a
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-parents-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed zkSync formatters.
173 changes: 170 additions & 3 deletions src/chains/zksync/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,73 @@ describe('block', () => {
"uncles": [],
}
`)

expect(
block.format({
hash: '0x288c26fa1cc1814b638f3010f20d17fc5d1a2667fb5aa1dd6354ad889fa335b4',
parentHash:
'0xb1f996bdcc7c1f1893b016bd47150a846ac1e11f443d23df4cbc7c36fa1d4ae1',
sha3Uncles:
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
miner: '0x0000000000000000000000000000000000000000',
stateRoot:
'0x0000000000000000000000000000000000000000000000000000000000000000',
transactionsRoot:
'0x0000000000000000000000000000000000000000000000000000000000000000',
receiptsRoot:
'0x0000000000000000000000000000000000000000000000000000000000000000',
number: '0x232223',
l1BatchNumber: null,
gasUsed: '0x20d70b',
gasLimit: '0xffffffff',
baseFeePerGas: '0xee6b280',
extraData: '0x',
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
timestamp: '0x64495efe',
l1BatchTimestamp: null,
difficulty: '0x0',
totalDifficulty: '0x0',
sealFields: [],
uncles: [],
transactions: [
'0xae443579604b132e8e8a9a03a09f4ba1c8387190d4feac2f60283a6df564b66c',
],
size: '0x0',
mixHash:
'0x0000000000000000000000000000000000000000000000000000000000000000',
nonce: '0x0000000000000000',
}),
).toMatchInlineSnapshot(`
{
"baseFeePerGas": 250000000n,
"difficulty": 0n,
"extraData": "0x",
"gasLimit": 4294967295n,
"gasUsed": 2152203n,
"hash": "0x288c26fa1cc1814b638f3010f20d17fc5d1a2667fb5aa1dd6354ad889fa335b4",
"l1BatchNumber": null,
"l1BatchTimestamp": null,
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x0000000000000000000000000000000000000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"number": 2302499n,
"parentHash": "0xb1f996bdcc7c1f1893b016bd47150a846ac1e11f443d23df4cbc7c36fa1d4ae1",
"receiptsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"sealFields": [],
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": 0n,
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": 1682530046n,
"totalDifficulty": 0n,
"transactions": [
"0xae443579604b132e8e8a9a03a09f4ba1c8387190d4feac2f60283a6df564b66c",
],
"transactionsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"uncles": [],
}
`)
})

test('action', async () => {
Expand Down Expand Up @@ -311,6 +378,59 @@ describe('transaction', () => {
"value": 1000000000000000000n,
}
`)

expect(
transaction.format({
accessList: [],
blockHash:
'0xf24f67fb9f8fb300164045fe6ba409acb03904e680ec7df41ed2d331dc38f545',
blockNumber: '0x1',
chainId: '0x104',
from: '0x36615cf349d7f6344891b1e7ca7c72883f5dc049',
gas: '0x0',
gasPrice: undefined,
hash: '0xf24f67fb9f8fb300164045fe6ba409acb03904e680ec7df41ed2d331dc38f545',
input:
'0x02f87582010480840ee6b280840ee6b2808312b84b94a61464658afeaf65cccaafd3a512b69a83b77618880de0b6b3a764000080c080a08ab03d8a1aa4ab231867d9b12a1d7ebacaec3395cf9c4940674f83d79e342e4ca0475dda75d501e72fd816a9699f02af05ef7305668ee4acd0e25561d4628758a3',
l1BatchNumber: null,
maxFeePerGas: '0xee6b280',
maxPriorityFeePerGas: '0xee6b280',
nonce: '0x0',
r: '0x0',
s: '0x0',
to: '0xa61464658afeaf65cccaafd3a512b69a83b77618',
transactionIndex: '0x1',
type: '0x2',
v: '0x104',
value: '0xde0b6b3a7640000',
l1BatchTxIndex: null,
}),
).toMatchInlineSnapshot(`
{
"accessList": [],
"blockHash": "0xf24f67fb9f8fb300164045fe6ba409acb03904e680ec7df41ed2d331dc38f545",
"blockNumber": 1n,
"chainId": 260,
"from": "0x36615cf349d7f6344891b1e7ca7c72883f5dc049",
"gas": 0n,
"gasPrice": undefined,
"hash": "0xf24f67fb9f8fb300164045fe6ba409acb03904e680ec7df41ed2d331dc38f545",
"input": "0x02f87582010480840ee6b280840ee6b2808312b84b94a61464658afeaf65cccaafd3a512b69a83b77618880de0b6b3a764000080c080a08ab03d8a1aa4ab231867d9b12a1d7ebacaec3395cf9c4940674f83d79e342e4ca0475dda75d501e72fd816a9699f02af05ef7305668ee4acd0e25561d4628758a3",
"l1BatchNumber": null,
"l1BatchTxIndex": null,
"maxFeePerGas": 250000000n,
"maxPriorityFeePerGas": 250000000n,
"nonce": 0,
"r": "0x0",
"s": "0x0",
"to": "0xa61464658afeaf65cccaafd3a512b69a83b77618",
"transactionIndex": 1,
"type": "eip1559",
"typeHex": "0x2",
"v": 260n,
"value": 1000000000000000000n,
}
`)
})

test('action - Priority', async () => {
Expand Down Expand Up @@ -668,7 +788,7 @@ describe('transaction receipt', () => {
blockHash:
'0xfd73aaef0e91fcd6c171056b235a2b0f17650dcbe17038d17f76bbf3980c4da2',
blockNumber: '0x8acd',
l1BatchNumber: '0x239',
l1BatchNumber: null,
transactionHash:
'0xe56c11904d690e1bd41a7e901df609c2dc011d1033415379193ebc4197f32fc6',
transactionIndex: '0x0',
Expand Down Expand Up @@ -707,7 +827,7 @@ describe('transaction receipt', () => {
effectiveGasPrice: '0xee6b280',
}),
).toMatchInlineSnapshot(`
{
{
"blockHash": "0xfd73aaef0e91fcd6c171056b235a2b0f17650dcbe17038d17f76bbf3980c4da2",
"blockNumber": 35533n,
"contractAddress": null,
Expand Down Expand Up @@ -881,7 +1001,7 @@ describe('transaction receipt', () => {
"blockHash": "0xfd73aaef0e91fcd6c171056b235a2b0f17650dcbe17038d17f76bbf3980c4da2",
"blockNumber": 35533n,
"data": "0x0000000000000000000000000000000000000000000000000000000009f623220000000000000000000000000000000000beaac4bd1b7f557aaca0ff08cfb011",
"l1BatchNumber": 569n,
"l1BatchNumber": null,
"logIndex": 9,
"logType": null,
"removed": false,
Expand Down Expand Up @@ -922,6 +1042,53 @@ describe('transaction receipt', () => {
"type": "0x71",
}
`)

expect(
transactionReceipt.format({
transactionHash:
'0xe56c11904d690e1bd41a7e901df609c2dc011d1033415379193ebc4197f32fc6',
transactionIndex: '0x0',
blockHash:
'0xfd73aaef0e91fcd6c171056b235a2b0f17650dcbe17038d17f76bbf3980c4da2',
blockNumber: '0x8acd',
l1BatchTxIndex: null,
l1BatchNumber: null,
from: '0xef9e8e39782b1b544a6eb6db6aa85207bacb4c20',
to: '0x8b791913eb07c32779a16750e3868aa8495f5964',
cumulativeGasUsed: '0x0',
gasUsed: '0x318fd7',
contractAddress: null,
logs: [],
l2ToL1Logs: [],
status: '0x1',
root: '0xfd73aaef0e91fcd6c171056b235a2b0f17650dcbe17038d17f76bbf3980c4da2',
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
type: '0x71',
effectiveGasPrice: '0xee6b280',
}),
).toMatchInlineSnapshot(`
{
"blockHash": "0xfd73aaef0e91fcd6c171056b235a2b0f17650dcbe17038d17f76bbf3980c4da2",
"blockNumber": 35533n,
"contractAddress": null,
"cumulativeGasUsed": 0n,
"effectiveGasPrice": 250000000n,
"from": "0xef9e8e39782b1b544a6eb6db6aa85207bacb4c20",
"gasUsed": 3248087n,
"l1BatchNumber": null,
"l1BatchTxIndex": null,
"l2ToL1Logs": [],
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"root": "0xfd73aaef0e91fcd6c171056b235a2b0f17650dcbe17038d17f76bbf3980c4da2",
"status": "success",
"to": "0x8b791913eb07c32779a16750e3868aa8495f5964",
"transactionHash": "0xe56c11904d690e1bd41a7e901df609c2dc011d1033415379193ebc4197f32fc6",
"transactionIndex": 0,
"type": "0x71",
}
`)
})

test('action', async () => {
Expand Down
8 changes: 6 additions & 2 deletions src/chains/zksync/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ export const formattersZkSync = {
return formatted
}) as Hash[] | ZkSyncTransaction[]
return {
l1BatchNumber: hexToBigInt(args.l1BatchNumber),
l1BatchTimestamp: hexToBigInt(args.l1BatchTimestamp),
l1BatchNumber: args.l1BatchNumber
? hexToBigInt(args.l1BatchNumber)
: null,
l1BatchTimestamp: args.l1BatchTimestamp
? hexToBigInt(args.l1BatchTimestamp)
: null,
transactions,
}
},
Expand Down
14 changes: 7 additions & 7 deletions src/chains/zksync/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type ZkSyncLog<
? TAbiEvent['name']
: undefined,
> = Log_<TQuantity, TIndex, TPending, TAbiEvent, TStrict, TAbi, TEventName> & {
l1BatchNumber: TQuantity
l1BatchNumber: TQuantity | null
transactionLogIndex: TIndex
logType: Hex | null
}
Expand Down Expand Up @@ -125,8 +125,8 @@ export type ZkSyncBlock<
// Block (RPC)

export type ZkSyncRpcBlockOverrides = {
l1BatchNumber: Hex
l1BatchTimestamp: Hex
l1BatchNumber: Hex | null
l1BatchTimestamp: Hex | null
}
export type ZkSyncRpcBlock<
TBlockTag extends BlockTag = BlockTag,
Expand Down Expand Up @@ -178,8 +178,8 @@ export type ZkSyncTransaction<TPending extends boolean = boolean> =
// Transaction (RPC)

type RpcTransactionOverrides = {
l1BatchNumber: Hex
l1BatchTxIndex: Hex
l1BatchNumber: Hex | null
l1BatchTxIndex: Hex | null
}

type RpcTransactionLegacy<TPending extends boolean = boolean> =
Expand Down Expand Up @@ -269,8 +269,8 @@ export type ZkSyncTransactionType = TransactionType | 'eip712' | 'priority'
// https://era.zksync.io/docs/api/js/types.html#transactionreceipt

export type ZkSyncRpcTransactionReceiptOverrides = {
l1BatchNumber: Hex
l1BatchTxIndex: Hex
l1BatchNumber: Hex | null
l1BatchTxIndex: Hex | null
logs: ZkSyncRpcLog[]
l2ToL1Logs: ZkSyncRpcL2ToL1Log[]
root: Hex
Expand Down

0 comments on commit c2fab4a

Please sign in to comment.